简体   繁体   中英

virtualenv uses wrong pip folder

I have a new macbook then I need to reconfigure my tools. Python 3 in installed throught brew, virtualenv and virtualwrapper are installed with pip. When I create a new environnement, I can use pip to install packages but python does not see them. Python can only use the packages installed outside the virtualenv. Any idea to solve it?

mbp:f4mily-1st sebastienmorele$ mkvirtualenv test
Using base prefix '/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7'
New python executable in /Users/sebastienmorele/.virtualenvs/test/bin/python3.7
Also creating executable in /Users/sebastienmorele/.virtualenvs/test/bin/python
Installing setuptools, pip, wheel...
done.
virtualenvwrapper.user_scripts creating /Users/sebastienmorele/.virtualenvs/test/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/sebastienmorele/.virtualenvs/test/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/sebastienmorele/.virtualenvs/test/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/sebastienmorele/.virtualenvs/test/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/sebastienmorele/.virtualenvs/test/bin/get_env_details
(test) mbp:f4mily-1st sebastienmorele$ pip install selenium
Collecting selenium
  Using cached https://files.pythonhosted.org/packages/80/d6/4294f0b4bce4de0abf13e17190289f9d0613b0a44e5dd6a7f5ca98459853/selenium-3.141.0-py2.py3-none-any.whl
Collecting urllib3 (from selenium)
  Using cached https://files.pythonhosted.org/packages/e6/60/247f23a7121ae632d62811ba7f273d0e58972d75e58a94d329d51550a47d/urllib3-1.25.3-py2.py3-none-any.whl
Installing collected packages: urllib3, selenium
Successfully installed selenium-3.141.0 urllib3-1.25.3
(test) mbp:f4mily-1st sebastienmorele$ python
Python 3.7.4 (default, Sep  7 2019, 18:27:02) 
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import selenium
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'selenium'
>>> 
(test) mbp:f4mily-1st sebastienmorele$ 
(test) mbp:f4mily-1st sebastienmorele$ deactivate 
mbp:f4mily-1st sebastienmorele$ pip list
Package           Version
----------------- -------
pbr               5.4.3  
pip               19.2.3 
setuptools        41.0.1 
six               1.12.0 
stevedore         1.31.0 
urllib3           1.25.3 
virtualenv        16.7.5 
virtualenv-clone  0.5.3  
virtualenvwrapper 4.8.4  
wheel             0.33.4 
mbp:f4mily-1st sebastienmorele$ pip install selenium
Collecting selenium
  Using cached https://files.pythonhosted.org/packages/80/d6/4294f0b4bce4de0abf13e17190289f9d0613b0a44e5dd6a7f5ca98459853/selenium-3.141.0-py2.py3-none-any.whl
Requirement already satisfied: urllib3 in /usr/local/lib/python3.7/site-packages (from selenium) (1.25.3)
Installing collected packages: selenium
Successfully installed selenium-3.141.0
mbp:f4mily-1st sebastienmorele$ workon test
(test) mbp:f4mily-1st sebastienmorele$ python
Python 3.7.4 (default, Sep  7 2019, 18:27:02) 
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import selenium
>>> 

If you're trying to access the packages installed in a virtualenv outside of it, then that defeats the whole point of virtual environments.

a self-contained directory tree that contains a Python installation for a particular version of Python, plus a number of additional packages.

more info here

no worries, it's pretty understandable, click on it.

And secondly, if you're already in your virtual environment and still not able to find those packages you've already installed, see how you installed them.

if you use pip install *package* , then the packages have been installed on python2.* environment.

Given that you're using python3.*, try pip3 install *package* command and then check for packages.

thank your for your answer. I know how to use virtualenv. using pip3 does not solve my issue:

(test) [~/projets/adsence_autovisit]$ pip3 install requests
Collecting requests
  Using cached https://files.pythonhosted.org/packages/51/bd/23c926cd341ea6b7dd0b2a00aba99ae0f828be89d72b2190f27c11d4b7fb/requests-2.22.0-py2.py3-none-any.whl
Requirement already satisfied: certifi>=2017.4.17 in /Users/sebastienmorele/.virtualenvs/test/lib/python3.7/site-packages (from requests) (2019.9.11)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /Users/sebastienmorele/.virtualenvs/test/lib/python3.7/site-packages (from requests) (1.25.5)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /Users/sebastienmorele/.virtualenvs/test/lib/python3.7/site-packages (from requests) (3.0.4)
Requirement already satisfied: idna<2.9,>=2.5 in /Users/sebastienmorele/.virtualenvs/test/lib/python3.7/site-packages (from requests) (2.8)
Installing collected packages: requests
Successfully installed requests-2.22.0
(test) [~/projets/adsence_autovisit]$ python
Python 3.7.4 (default, Sep  7 2019, 18:27:02) 
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'requests'
>>> 

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