简体   繁体   中英

Running script without virtualenv activation

Is there a difference between running script using virtualenv interpreter (without virtualenv activation) and running it in activated virtualenv?

venv/bin/python some_script.py

vs

source venv/bin/activate
python some_script.py

Running source bin/activate will set the PATH variable to point to your environment bin directory which is useful if you have other command line scripts/binaries installed (this can happen with certain python packages that add shell commands), it will also unset/set PYTHONHOME.

So, if bin/python works for you then you're fine but if some of the packages you're using start behaving strangely (or wrong one gets imported) it's probably because Python is getting the wrong PYTHONHOME or because a certain script is not found in PATH.

Yes. Virtualenv creates an interpreter in its own right. Just do this,

which python

For each interpreter, virtualenv and your normal interpreter and see what happens. They will show you two different links to python interpreter. Here's my example:

quazinafiulislam@Nafiuls-Mac: ~/Code/Python/PyTestingZone
 $ which python                                                                                               [7:49:26]
/Users/quazinafiulislam/.pyenv/shims/python

quazinafiulislam@Nafiuls-Mac: ~/Code/Python/PyTestingZone
 $ source .venv/bin/activate                                                                                  [7:49:29]
(.venv)
quazinafiulislam@Nafiuls-Mac: ~/Code/Python/PyTestingZone
 $ which python                                                                                               [7:49:35]
/Users/quazinafiulislam/Code/Python/PyTestingZone/.venv/bin/python

是的,只需检查您的环境变量是否有激活,以查看您将丢失的内容。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM