问题
I am running "chalice local" inside virtual environment. I don't see the libraries installed in virtual environment. From inside chalicelib/common.py file, I see the path(sys.path) to be set at:
['/home/sudip/myapp', '/usr/local/bin', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages']
But when I run python3.6 from virtual environment console, I see this:
(venv) myapp$ python3.6
Python 3.6.5 (default, Mar 29 2018, 03:28:50)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print (sys.path)
['', '/home/sudip/myapp/venv/lib/python36.zip', '/home/sudip/myapp/venv/lib/python3.6', '/home/sudip/myapp/venv/lib/python3.6/lib-dynload', '/usr/lib/python3.6', '/home/sudip//myapp/venv/lib/python3.6/site-packages']
>>>
Here the path is properly set.Why its not happening in former case. Hence I am getting lot of module import errors when I run my application, as for example: ModuleNotFoundError: No module named 'jwt'. Can anybody help?
Thanks, Sudip
回答1:
You need to create your virtualenv with the option --system-site-packages
to get access to the system (and site) packages:
virtualenv -p python3 --system-site-packages myvenv
来源:https://stackoverflow.com/questions/50500023/sys-path-in-virtualenv-python