Both sides previous revision
Previous revision
Next revision
|
Previous revision
|
python [2019/12/02 17:54] popel |
python [2023/02/14 11:13] (current) jindra.helcl update |
In this guide, I expect you are using Python3 (and ''pip3''), but (for old projects) you can use Python2 (and ''pip2'') as well. | In this guide, I expect you are using Python3 (and ''pip3''), but (for old projects) you can use Python2 (and ''pip2'') as well. |
| |
* You can use the system Python (currently 3.6.*, in Ubuntu 18.04) | * You can use the system Python |
* You can use any Python from ''/opt/python/'', e.g. for 3.7.0 add the following line to your .bashrc: <code>export PATH=/opt/python/3.7.0/bin:"${PATH}"</code> | * You can use any Python from ''/opt/python/'', e.g. for 3.11.0 add the following line to your .bashrc: <code>export PATH=/opt/python/3.11.0/bin:"${PATH}"</code> |
* You can install modules with ''pip3''. If you are not using any [[#virtual environments]], you must add the ''-''''-user'' option, so it is installed in your home. In this case, don't forget the executable scripts are installed in ''~/.local/bin/'', so add the following line to your .bashrc: <code>export PATH=~/.local/bin:"${PATH}"</code> | * You can install modules with ''pip''. It is recommended to use [[#virtual environments]] for installing new packages. If you are not using virtual environments, you must add the ''-''''-user'' option, so it is installed in your home. In this case, don't forget the executable scripts are installed in ''~/.local/bin/'', so add the following line to your .bashrc: <code>export PATH=~/.local/bin:"${PATH}"</code> |
* Both the system Python3 and the Python3 from ''/opt/python/'' come with an old version of pip3, so it is recommended to update it with <code>pip3 install --user --upgrade pip</code> | * Both the system Python3 and the Python3 from ''/opt/python/'' come with an old version of pip3, so it is recommended to update it with <code>pip3 install --user --upgrade pip</code> |
* There are no UFAL-wide pre-installed Python modules. You need to install all modules you need yourself (with pip3). | * There are no UFAL-wide pre-installed Python modules. You need to install all modules you need yourself (with pip3). |
You can use [[https://docs.python.org/3/tutorial/venv.html|virtual environments]], e.g. one for each project (or a group of projects), so the version requirements of different projects do not collide. | You can use [[https://docs.python.org/3/tutorial/venv.html|virtual environments]], e.g. one for each project (or a group of projects), so the version requirements of different projects do not collide. |
| |
Create a new virtual environment with | Create a new virtual environment with: |
python3 -m venv my-project-name | python3 -m venv my-project-name |
| or (for a specific version of python): |
| /opt/python/$PYTHON_VERSION/bin/python3 -m venv my-project-name |
| |
where ''my-project-name'' can be a relative or absolute path to a directory which will be created. | where ''my-project-name'' can be a relative or absolute path to a directory which will be created. |
**Caveat1:** the path to the directory should be rather short, there is a limit on shebang paths so you can get strange errors like ''ipython3: bad interpreter: No such file or directory'' if your ipython3 is installed in the venv starts with ''#!/..a..very..long..path..'' | **Caveat1:** the path to the directory should be rather short, there is a limit on shebang paths so you can get strange errors like ''ipython3: bad interpreter: No such file or directory'' if your ipython3 is installed in the venv starts with ''#!/..a..very..long..path..'' |