0

I am trying to download libraries for python 3. Running just pip install pycrypto or any other library not already installed gives me a huge error

I posted about in another Q: Using pip to install pycrypto library on mac

Using sudo says the library is installed successfully, yet I still get the ModuleNotFoundError when running my program. (I am using MacOS High Sierra)

$ sudo pip install pycrypto
Password:
The directory '/Users/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pycrypto
  Downloading https://files.pythonhosted.org/packages/60/db/645aa9af249f059cc3a368b118de33889219e0362141e75d4eaf6f80f163/pycrypto-2.6.1.tar.gz (446kB)
    100% |████████████████████████████████| 450kB 2.3MB/s 
Installing collected packages: pycrypto
  Running setup.py install for pycrypto ... done
Successfully installed pycrypto-2.6.1
You are using pip version 9.0.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

$ python ./assignment1.py 
Traceback (most recent call last):
  File "./assignment1.py", line 3, in <module>
    import pycrypto
ModuleNotFoundError: No module named 'pycrypto'
Nic3500
  • 8,144
  • 10
  • 29
  • 40
user1039484
  • 39
  • 1
  • 7
  • Possible duplicate of [Is it acceptable and safe to run pip install under sudo?](https://stackoverflow.com/questions/15028648/is-it-acceptable-and-safe-to-run-pip-install-under-sudo) – dmulter Oct 14 '18 at 01:18
  • This could be because there isn't any command like `import pycrypto` – Upasana Mittal Oct 14 '18 at 02:49
  • @UpasanaMittal how would I utilize the library then? – user1039484 Oct 14 '18 at 04:52
  • What does `pip -V` and `python -V` output? Aside from the advice "never use `sudo pip install`, always `pip install --user`". – hoefling Oct 14 '18 at 07:39
  • Also, it looks like you're on MacOS - do you use system Python or did you install additional Python versions? How did you install them? Did you brew or did you use installers from python.org? What does `which -a python` return? – hoefling Oct 14 '18 at 07:43
  • @hoefling pip -V: pip 9.0.1 from /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg (python 2.7), python -V: Python 3.6.5. – user1039484 Oct 14 '18 at 15:17
  • @hoefling I think I used brew, but it was a while ago so not completely sure. which -a python: /usr/local/bin/python /usr/bin/python – user1039484 Oct 14 '18 at 15:18
  • Well now you can surely see for yourself what goes wrong - `pip` serves the Python 2 installation, so `pip install anything` will install `anything` for Python 2. Your `python` command starts Python 3.6, which will not find the modules installed for Python 2. Solution is using the correct `pip` - check whether you have `pip3` or `pip3.6` (use `which` for that), then issue e.g. `pip3 install --user pycrypto`. – hoefling Oct 14 '18 at 15:23
  • @hoefling using pip3 the install worked! However, when I try to compile my program I still get the "$ python ./assignment1.py Traceback (most recent call last): File "./assignment1.py", line 3, in import pycrypto ModuleNotFoundError: No module named 'pycrypto" error – user1039484 Oct 14 '18 at 15:45
  • I haven't used pycrypto but after going through its tutorials, i nowhere saw that it could be imported like `import pycrypto` – Upasana Mittal Oct 14 '18 at 16:04
  • Can you try commands from here? https://www.laurentluce.com/posts/python-and-cryptography-with-pycrypto/. I know i could be wrong as well but can you give it a try – Upasana Mittal Oct 14 '18 at 16:05
  • 1
    It should be `import Crypto`, not `import pycrypto`. – hoefling Oct 14 '18 at 16:31

0 Answers0