简体   繁体   English

无法在我的virtualenv中导入模块

[英]Can’t import a module within my virtualenv

I'm very new to Python and web development. 我是Python和Web开发的新手。 I created a Python project and now I want to import an external library. 我创建了一个Python项目,现在我想导入一个外部库。

I want to import the apans-client library, and this is what I've done: 我想导入apans-client库,这就是我所做的:

  1. Download and extract the package from https://pypi.python.org/pypi/apns-client https://pypi.python.org/pypi/apns-client下载并解压缩软件包
  2. Install the package on the command line: 在命令行上安装软件包:

     $ cd apns-client-0.2.1 $ /Users/myuser/env/bin/python setup.py install 

    The installation runs and seems to complete successfully: 安装将运行,并且似乎已成功完成:

     running install running bdist_egg running egg_info writing requirements to apns_client.egg-info/requires.txt .. .. .. Installed /Users/myuser/env/lib/python2.7/site-packages/pycparser-2.10-py2.7.egg Finished processing dependencies for apns-client==0.2.1 

    Here env is a virtualenv folder where my project is location. 这里的env是我的项目所在的virtualenv文件夹。

But if I add import apnsclient to one of my scripts and try to run it, then I get an error: 但是,如果我将import apnsclient添加到我的一个脚本中并尝试运行它,则会收到错误消息:

 No module named apnsclient.

What am I missing? 我想念什么?

Update 更新

I use PyCharm, and the Project Interpreter is pointing to a different Python installation: 我使用PyCharm,并且Project Interpreter指向另一种Python安装:

/Library/Framework/Python.framework/3.4/bin/python3

I changed the path to ~/env , but then I got the following error: 我将路径更改为~/env ,但是随后出现以下错误:

Failed modules 失败的模块
Python 2.7.8 virtualenv at ~/env Python 2.7.8 virtualenv位于~/env
- Nav -导航
generation of skeletons for the modules above will be tried again when the modules are updated or a new version of generator is available. 更新模块或使用新版本的generator时,将再次尝试生成上述模块的框架。

Activate your virtualenv first, then install apans-client: 首先激活您的virtualenv,然后安装apans-client:

 $ cd /Users/myuser/env
 $ source bin/activate
 $ cd /path/to/apns-client-0.2.1  
 $ python setup.py install # Activating the virtualenv should ensure correct python is used

I use PyCharm, thanks to all the comment I got here I noticed that the Project Interpreter was pointing to a different Python installation than the one in ~/env. 我使用PyCharm,这要归功于我收到的所有注释,我注意到Project Interpreter指向的Python安装不同于〜/ env中的安装。

after changing it the issue was fixed. 更改后,此问题已解决。

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

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