Virtual Environment: Unterschied zwischen den Versionen
Aus Wiki
| (5 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt) | |||
| Zeile 14: | Zeile 14: | ||
virtualenv -p /usr/bin/python3.7 my-env | virtualenv -p /usr/bin/python3.7 my-env | ||
| + | |||
| + | change python version of virtual environment | ||
| + | |||
| + | virtualenv --python=/usr/bin/python3.7 my-env | ||
install package in venv with python 3 | install package in venv with python 3 | ||
pip3 install <package>[==<version>] | pip3 install <package>[==<version>] | ||
| + | or | ||
| + | sudo <path-to-venv>/bin/python3.7 -m pip install <package>[==<version>] | ||
| + | |||
| + | Install GDAL in venv: | ||
| + | |||
| + | pip3 install --global-option=build_ext --global-option="-I/usr/include/gdal" GDAL==`gdal-config --version` | ||
| + | |||
| + | Activate virtual environment in python3 script | ||
| + | |||
| + | #!/usr/bin/python3 | ||
| + | activate_this = '/local/www/venv-python3.7-django3.1/bin/activate_this.py' | ||
| + | with open(activate_this) as file_: | ||
| + | exec(file_.read(), dict(__file__=activate_this)) | ||
Aktuelle Version vom 26. April 2021, 10:50 Uhr
create virtual environment 'my-env'
virtualenv my-env
start virtual environment
source my-env/bin/activate
end virtual environment
deactivate
set default python version for virtual environment
virtualenv -p /usr/bin/python3.7 my-env
change python version of virtual environment
virtualenv --python=/usr/bin/python3.7 my-env
install package in venv with python 3
pip3 install <package>[==<version>] or sudo <path-to-venv>/bin/python3.7 -m pip install <package>[==<version>]
Install GDAL in venv:
pip3 install --global-option=build_ext --global-option="-I/usr/include/gdal" GDAL==`gdal-config --version`
Activate virtual environment in python3 script
#!/usr/bin/python3
activate_this = '/local/www/venv-python3.7-django3.1/bin/activate_this.py'
with open(activate_this) as file_:
exec(file_.read(), dict(__file__=activate_this))