简体   繁体   中英

Can’t import a module within my virtualenv

I'm very new to Python and web development. I created a Python project and now I want to import an external library.

I want to import the apans-client library, and this is what I've done:

  1. Download and extract the package from 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.

But if I add import apnsclient to one of my scripts and try to run it, then I get an error:

 No module named apnsclient.

What am I missing?

Update

I use PyCharm, and the Project Interpreter is pointing to a different Python installation:

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

I changed the path to ~/env , but then I got the following error:

Failed modules
Python 2.7.8 virtualenv at ~/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.

Activate your virtualenv first, then install 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.

after changing it the issue was fixed.

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