... | @@ -1901,4 +1901,45 @@ As you can see from the example above, the Python package(s) will be installed i |
... | @@ -1901,4 +1901,45 @@ As you can see from the example above, the Python package(s) will be installed i |
|
|
|
|
|
**Location: /home/username/.local/lib/python3.6/site-packages**
|
|
**Location: /home/username/.local/lib/python3.6/site-packages**
|
|
|
|
|
|
|
|
### Python virtual environments
|
|
|
|
If you are working on different projects and you need different Python packages for each project, it is better to work in a special virtual environment.
|
|
|
|
|
|
|
|
When you activate this virtual environment, it will create a special virtual Python environment for you.
|
|
|
|
In this virtual environment you can use the **pip** command (without the --user option) and other command.
|
|
|
|
|
|
|
|
You create a new virtual environment with the command:
|
|
|
|
* $ virtualenv envname
|
|
|
|
|
|
|
|
You activate a new virtual environment with the command:
|
|
|
|
* $ source envname/bin/activate
|
|
|
|
|
|
|
|
You deactivate a virtual environment with the command (it will not be destroyed):
|
|
|
|
* (envname) $ deactivate
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```
|
|
|
|
virtualenv Project-A
|
|
|
|
Using base prefix '/usr'
|
|
|
|
New python executable in /home/username/Project-A/bin/python3.6
|
|
|
|
Also creating executable in /home/username/Project-A/bin/python
|
|
|
|
Installing setuptools, pip, wheel...done.
|
|
|
|
|
|
|
|
|
|
|
|
[username@res-hpc-lo01 ~]$ source Project-A/bin/activate
|
|
|
|
(Project-A) [username@res-hpc-lo01 ~]$
|
|
|
|
|
|
|
|
(Project-A) [username@res-hpc-lo01 ~]$ deactivate
|
|
|
|
[username@res-hpc-lo01 ~]$
|
|
|
|
|
|
|
|
|
|
|
|
(Project-A) [username@res-hpc-lo01 python3.6]$ pip3 list
|
|
|
|
Package Version
|
|
|
|
---------- -------
|
|
|
|
pip 20.1.1
|
|
|
|
setuptools 49.1.0
|
|
|
|
wheel 0.34.2
|
|
|
|
|
|
|
|
|
|
|
|
(Project-A) [username@res-hpc-lo01 ~]$ deactivate
|
|
|
|
[username@res-hpc-lo01 ~]$
|
|
|
|
``` |