简体   繁体   中英

Cannot upgrade packages using pip inside virtualenv

I wanted to be able to access all of my site packages from another installation of Python, so I created a virtual environment in this way:

venv my_project --system-site-packages

I noticed that my version of Keras was outdated, so from within my virtualenv, I executed:

pip install keras

which worked without an issue. I'm using pip version 9.0.1

I'm trying to run a python program that uses TensorFlow, but when I run it, I get an error:

ImportError: No module named tensorboard.plugins

I googled around and found that I needed to upgrade TensorFlow. I tried several commands:

(my_project/) user@GPU5:~/spatial/zero_padded/powerlaw$ pip install tensorflow 

The above gives me a 'requirement already satisfied' error.

$ pip install --target=~/spatial/zero_padded/powerlaw/my_project/ --upgrade tensorflow
Collecting tensorflow
  Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow

The output of which python :

/user/spatial/zero_padded/powerlaw/my_project/bin/python

I think my PYTHONPATH is the first line in this:

(my_project/) user@GPU5:~/spatial/zero_padded/powerlaw/my_project$ python -c "import sys; print '\n'.join(sys.path)"

/user/spatial/zero_padded/powerlaw/my_project
/opt/enthought/canopy-1.5.1/appdata/canopy-1.5.1.2730.rh5-x86_64/lib/python27.zip
/opt/enthought/canopy-1.5.1/appdata/canopy-1.5.1.2730.rh5-x86_64/lib/python2.7
/opt/enthought/canopy-1.5.1/appdata/canopy-1.5.1.2730.rh5-x86_64/lib/python2.7/plat-linux2
/opt/enthought/canopy-1.5.1/appdata/canopy-1.5.1.2730.rh5-x86_64/lib/python2.7/lib-tk
/opt/enthought/canopy-1.5.1/appdata/canopy-1.5.1.2730.rh5-x86_64/lib/python2.7/lib-old
/opt/enthought/canopy-1.5.1/appdata/canopy-1.5.1.2730.rh5-x86_64/lib/python2.7/lib-dynload
/user/spatial/zero_padded/powerlaw/my_project/lib/python2.7/site-packages
/user/pkgs/enthought/canopy-1.5.1/lib/python2.7/site-packages
/user/pkgs/enthought/canopy-1.5.1/lib/python2.7/site-packages/PIL
/opt/enthought/canopy-1.5.1/appdata/canopy-1.5.1.2730.rh5-x86_64/lib/python2.7/site-packages

How do I upgrade TensorFlow inside my virtualenv?

Pretty sure that all you need to do is run pip install with -U to upgrade the package inside the virtualenv:

(my_project/) user@GPU5:~/spatial/zero_padded/powerlaw$ pip install -U tensorflow

-U is just shorthand for --upgrade . But, you should really go ahead and create a dependencies file for yourself called requirements.txt that lives in the project root and specify version numbers there.

eg,

tensorflow==1.2.0

And that makes it easier to install all requirements

pip install -r requirements.txt

The best way to do it is install the dependencies outside de vm, and create a new one I'm afraid to say that. Because doing upgrades is different than installing

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