简体   繁体   English

使用Anaconda安装包

[英]Installing packages with Anaconda

On Ubuntu 14.04, I have installed Anaconda, which I use as my main Python interpreter. 在Ubuntu 14.04上,我安装了Anaconda,我用它作为我的主要Python解释器。 I now want to install the TensorFlow library and use this via Anaconda. 我现在想要安装TensorFlow库并通过Anaconda使用它。 So, I downloaded the relevant foo.whl file from the TensorFlow website, and then ran pip install foo.whl . 所以,我从TensorFlow网站下载了相关的foo.whl文件,然后运行了pip install foo.whl After this, I ran pip freeze , and it showed me tensorflow==0.7.1 indicating that it was installed successfully. 在此之后,我运行了pip freeze ,它显示了tensorflow==0.7.1表明它已成功安装。

However, using the Anaconda interpreter, when I run a Python file which has import tensorflow , it tells me ImportError: No module named 'tensorflow' . 但是,使用Anaconda解释器,当我运行具有import tensorflow的Python文件时,它告诉我ImportError: No module named 'tensorflow' Additionally, if I search my Anaconda directory, there is no reference to TensorFlow. 此外,如果我搜索我的Anaconda目录,则不会引用TensorFlow。

Now at first, I thought this was because pip install was using pip that comes with the native Ubuntu installation. 首先,我认为这是因为pip install正在使用本机Ubuntu安装附带的pip However, I have the line export PATH=/home/karnivaurus/Libraries/Anaconda/bin:$PATH in my .bashrc file, and so this suggests it would use Anaconda's pip. 但是,我的.bashrc文件中有行export PATH=/home/karnivaurus/Libraries/Anaconda/bin:$PATH ,所以这表明它会使用Anaconda的pip。

Any idea what's going on? 知道发生了什么事吗? Thanks! 谢谢!

You can try the similar answer here: https://stackoverflow.com/a/33698750/5573572 你可以在这里尝试类似的答案: https//stackoverflow.com/a/33698750/5573572

Pretty much do these steps: 几乎完成以下步骤:

1. Uninstall TensorFlow from pip:

pip uninstall tensorflow

Do the above to avoid conflicts. 做以上操作以避免冲突。

2. Install Python 3 in a virtual environment (version 0.7.1 as of this writing):

conda create -n <environment_name> python==3.5.1

3. Activate your virtual environment (do this every time you want to use TensorFlow):

source activate <environment_name>

4. Install a Conda version of TensorFlow in that environment (version 0.7.1 as of this writing):

conda install -c https://conda.anaconda.org/jjhelmus tensorflow

Remember to change "environment_name" to whatever you want to name your environment. 请记住将“environment_name”更改为您要为环境命名的任何内容。 After these, you should hopefully be able to import tensorflow. 在这些之后,你应该能够导入tensorflow。 If not, then anaconda might be having trouble installing TensorFlow's dependencies. 如果没有,那么anaconda可能在安装TensorFlow的依赖项时遇到问题。 I'll run this on my machine to check real quick :p. 我会在我的机器上运行这个以快速检查:p。 I have confirmed that this works. 我已经确认这是有效的。

A possible reason that your installation attempt was not working is because Ubuntu 14.04 has Python 2.7 installed, in which many system programs depend on for the time being. 安装尝试不起作用的一个可能原因是因为Ubuntu 14.04安装了Python 2.7,其中许多系统程序暂时依赖。 As an aside, the Ubuntu development team is working on porting all of those programs to use Python 3 instead: https://wiki.ubuntu.com/Python/Python35Transition 顺便说一句,Ubuntu开发团队正在努力将所有这些程序移植到使用Python 3: https//wiki.ubuntu.com/Python/Python35Transition

Update : added instructions to include creating a virtual environment. 更新 :添加了包含创建虚拟环境的说明。 The virtual environment helps because it allows you to use the Python commands within the environment instead of any system Python commands. 虚拟环境很有帮助,因为它允许您在环境中使用Python命令而不是任何系统Python命令。 So, commands like "pip" and "python" will use the ones in the environment, which also contains the TensorFlow libraries. 因此,像“pip”和“python”这样的命令将使用环境中的命令,其中还包含TensorFlow库。 To get out of the environment, do: 要离开环境,请执行以下操作:

source deactivate

Try without sudo : 尝试没有sudo

pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl

instead of 代替

sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl

First uninstall all the dependencies of tensorflow using 首先卸载tensorflow的所有依赖项

pip uninstall tensorflow

Then install tensorflow package with conda run: 然后用conda run安装tensorflow包:

 conda install -c jjhelmus tensorflow=0.10.0rc0

If you want to install tensorflow package with pip run: 如果你想用pip run安装tensorflow包:

pip install -i https://pypi.anaconda.org/jjhelmus/simple tensorflow

Sources: https://anaconda.org/jjhelmus/tensorflow 资料来源: https//anaconda.org/jjhelmus/tensorflow

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM