简体   繁体   English

Anaconda,通过pip安装Python软件包不起作用,Linux

[英]Anaconda, Python package install through pip not working, Linux

I am having issues installing packages using pip. 我在使用pip安装软件包时遇到问题。 When installing packages through conda from within my environment it works fine however when trying to install through pip I continue receiving the ImportError: No Module named X. 从我的环境中通过conda安装软件包时,它工作正常,但是当尝试通过pip安装时,我继续收到ImportError:No Module namedX。

The packages I am trying to install are a group of packages that are not apart of the conda distribution. 我尝试安装的软件包是一组不在conda发行版中的软件包。

Example

[sjamal@login1(franklin) src]$ source activate Py343

(Py343) [sjamal@login1(franklin) src]$ pip install pyvcf

Collecting pyvcf
Requirement already satisfied: setuptools in /users/sjamal/anaconda3/envs/Py343/lib/python3.4/site-packages/setuptools-27.2.0-py3.4.egg (from pyvcf)
Installing collected packages: pyvcf
Successfully installed pyvcf-0.6.8

(Py343) [sjamal@login1(franklin) src]$ python

Python 3.4.3 |Continuum Analytics, Inc.| (default, Oct 19 2015, 21:52:17) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.

>>> import vcf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'vcf'

In ~/.bashrc I have the following path added /users/sjamal/anaconda3/bin which obviously allows me to access anaconda, conda etc. 在〜/ .bashrc中,我添加了以下路径/ users / sjamal / anaconda3 / bin,这显然允许我访问anaconda,conda等。

I initially thought I had the same issue as in the question posed below. 我最初以为我遇到的问题与下面提出的问题相同。 But either I missunderstood the answer or its not the same issue. 但是我误解了答案,或者问题不一样。

Does anaconda create a separate PYTHONPATH variable for each new environment? anaconda是否为每个新环境创建一个单独的PYTHONPATH变量?

I am pretty certain that it is a path issue but my lack of understanding of how installation of packages through pip and conda to the respective environments is probably why I can't seem to solve it. 我可以肯定这是一个路径问题,但是我对如何通过pip和conda将软件包安装到各自的环境缺乏了解,可能就是为什么我似乎无法解决它。

Additional information: 附加信息:

I am on a login node on a cluster where I can't perform any root commands. 我在无法执行任何根命令的群集的登录节点上。 I am sure root access is not needed but thought it would be good to mention. 我确定不需要root访问,但我认为应该提一下。 My linux distribution is CentOS release 6.6 (Final). 我的Linux发行版是CentOS版本6.6(最终版)。

Thanks for taking a look at it! 感谢您的关注!

I managed to figure it out. 我设法弄清楚了。 After doing a bit of searching on my system. 在我的系统上做了一些搜索之后。 I found that pip and conda install the packages to two different locations. 我发现pip和conda将软件包安装到两个不同的位置。 In my case.. 就我而言

conda - Installed to my current anaconda environment just as expected
pip - /users/sjamal/gridware/share/python/2.7.8/lib/python3.6/site-packages/

I believe the reason for pip installing to a different location is due the predesigned infrastructure we have on our HPC, hence adding the following prefix below. 我相信将pip安装到其他位置的原因是由于我们在HPC上具有预先设计的基础架构,因此在下面添加了以下前缀。

/users/sjamal/gridware/share 

In order to use my packages there are 3 ways of doing this. 为了使用我的软件包,有3种方法。 Two of which I can do. 我可以做到两个。 The last one however I have not been able to figure out as it requires me to change pips default location to install packages. 但是最后一个我无法弄清楚,因为它要求我更改点的默认位置来安装软件包。 I tried using 我尝试使用

pip install -t <dir> 

Although it keeps throwing errors and won't allow me to choose the destination to install the folder. 尽管它总是抛出错误,并且不允许我选择安装文件夹的目的地。

The two other alternatives are: 另外两个选择是:

1. Install the packages using pip install <package> and then move the      packages to the original destination. 

2. Add the path to the environment where I want to have the packages installed to the local PATH variable in ~/.bashrc. However, this beats the fact of working in different environments as the package will be accessible from different environments.

If anyone knows how to redirect pip's default install destination I would be very grateful if you shared it with me. 如果有人知道如何重定向pip的默认安装目标,请与我共享。 Until then I will continue my search for a better alternative. 在此之前,我将继续寻找更好的选择。

Finally thank you @amrit for responding! 最后感谢@amrit的回复!

Cheers! 干杯!

try this first.. 先尝试一下..

$ python3 $ python3

 >>> import sys

 >>> sys.path.append('/all/path/to/C/Python')

 >>> import vcf

and if not working then... 如果不行的话...

install python 3.6.2 and ... write 安装python 3.6.2和...写

import vcf 

instead of 代替

import pyvcf

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

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