简体   繁体   中英

Cannot import a package installed with pip

I'm trying to add a package for my python(2.7.6) on linux , I used the command:

 pip install crc16

and It sends back :

Requirement already satisfied (use --upgrade to upgrade): crc16 in /usr/local/lib/python3.5/site-packages

As should be. But when i try to run a python script it says

 Traceback (most recent call last):
  File "mos.py", line 1, in <module>
    import crc16
ImportError: No module named crc16

My guess is that pip and the python aren't on the same version.

EDIT** answer: i used easy_install-2.7 crc16 and then python2.7 mos.py

你可以做到的

python -m pip install <module>

Your pip is catching the 3.5 version. You must specifically install pip for 2.7 version for your code to work. This is how it's done:

$ sudo apt-get install python2-pip
$ sudo pip2 install crc16

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