1

Good morning!

Quick summary: I'm having a problem with pip and virtualenv. Whether or not my virtualenv is activated my pip installs packages into the site-packages of the venv but when outside my venv python reads packages from a totally different folder (details below) which makes it so that I can't install packages for my python outside of venv. My guess is that I need to make sure that pip installs in different places when inside or outside of venv. I can't seem to find a config file for my pip where this is designated and most of the wabpages I've looked at are either not really relevant for my problem or way above my head...

Some details (I'm still new to working with ubuntu, linux, and the datails of python so if I'm missing any important information please say so and I will try to fill in with what's missing): Outside venv:

$which python

results in

usr/bin/python

and

$which pip

gives

/home/username/.local/bin/pip

I found that the python site package can identify where it's looking for packages so this is the output when using it (I also include what gave notified me of the problem):

$ python
Python 3.6.9 (default, Nov  7 2019, 10:44:02) 
[GCC 8.3.0] on linux
>>> import site
>>> print(site.getsitepackages())
['/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.6/dist-packages']
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
>>> exit()
$ pip install numpy
Requirement already satisfied: numpy in ./projectFolder/venv/lib/python3.6/site-packages (1.17.4)

Looking through the directories I can't find a site-package directory for python but I can find a dist-packages (as above) while in venv there is a site-packages where pip installs the packages.

Activating my venv gives the following results:

(venv)$ which python
/home/username/projectFolder/venv/bin/python
(venv)$ which pip
/home/username/projectFolder/venv/bin/pip

Using site under venv gives:

(venv)$ python
Python 3.6.9 (default, Nov  7 2019, 10:44:02) 
[GCC 8.3.0] on linux
>>> import site
>>> print(site.getsitepackages())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'site' has no attribute 'getsitepackages'
6
  • 1
    What OS/release are you using? python should start python 2.7, and python3 should start python3, and no current Ubuntu uses the version of python3 you display (packages.ubuntu.com/…) – guiverc Dec 25 '19 at 11:11
  • I'm using Ubuntu 18.04.3 and the command python runs python 3.6.9, as seen in the transcript above, if I'm not misunderstanding the output. – O. Carlsson Dec 26 '19 at 11:50
  • I misread your comment but I don't think it's relevant because I didn't have this problem before I donloaded and activated venv. I had som package problem with anaconda and venv so I uninstalled anaconda and reinstalled venv. Since that I've had this problem. – O. Carlsson Dec 26 '19 at 20:37
  • Many (older) Ubuntu tools are written to work with python, and python on Ubuntu should cause python 2.7 to run, python3 is used for python3. My own install (later release than yours thru release-upgrade) has 2.7.17 for python & 3.7.5 for python3 ; on the link I provided yours responded with a version not standard/tested, thus tools that were tested to work perfectly in the default 3.6.7 may have issues... I'm not a python person, can see you're not using a 'clean' Ubuntu system, so cannot help. (I don't know what you did to alter your system from standard; you haven't said) – guiverc Dec 26 '19 at 21:42
  • I'm new to Ubuntu and python so I unfortunately can't recall the details of stuff that I've done (I don't know what's important, that's also the problem when your asking for help in an area you don't know much about...). :( But my python command redirects to python3 (I don't think I've got 2.7 installed). Anyway, thank you for your time! – O. Carlsson Dec 27 '19 at 9:25
0

The problem is well described here by virtualenv maintainer: https://github.com/pypa/virtualenv/issues/737#issuecomment-319078189

I will quote his comment here:

The problem (as I understand it) is that virtualenv implements its own version of site.py that doesn't track the core Python version perfectly (that's the issue behind #355, referenced above - if you follow that link, and the link to the various issues linked from there, you'll get the background).

Fixing this isn't as simple as "sync up to the core site.py", because we need to support multiple Python versions, and site.py has changed between them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.