Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
966 views
in Technique[技术] by (71.8m points)

pip - PermissionError While Installing TensorFlow Using Virtualenv

I was installing tensorflow using virtualenv. The following commands worked fine.

$ virtualenv ~/.tensorflow/bin/activate
$ pip install --upgrade tensorflow

But if I try:

$ virtualenv ~/.tensorflow/bin/activate
$ pip3 install tensorflow

I got PermissionError:

enter image description here

I tried the last command with sudo.

$ sudo pip3 install tensorflow

Then it seems like I can import tensorflow outside virtualenv. (Is it correct?)

How can I install tensorflow for python 3 only inside virtualenv?

By the way, I am using pip 9.0.1 for both python 2.7.12 and 3.5.2.

The version of virtualenv is 15.0.1.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If your virtual environment is in python3. Running pip install tensorflow should install it in your python3 environment.

$ virtualenv3 venv 
$ source venv/bin/activate
(venv)$ pip install tensorflow
(venv)$ pip freeze
appdirs==1.4.3
numpy==1.12.1
packaging==16.8
protobuf==3.3.0
pyparsing==2.2.0
six==1.10.0
tensorflow==1.1.0
Werkzeug==0.12.2
(venv) $>python
Python 3.6.0 (default, Jan 16 2017, 12:12:55) 
[GCC 6.3.1 20170109] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> 

If you are running

virtualenv ~/.tensorflow/bin/activate

make sure virtualenv is for python3. And your virtual env will get created at ~/.tensorflow/bin/activate (Not sure if you want that). I'd suggest change that address to something simple, and make sure it does not contain the folder named as some of the libraries you want to import. It causes problems sometimes.

If you're trying to import tf in ipython3, you should also make sure that ipython is installed in the same environment. And if you run

ipython notebook

This will launch the default ipython (/usr/bin/ipython). You dont want that. So, run venv/bin/ipython3 instead


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...