简体   繁体   中英

after pip successful installed: ModuleNotFoundError

I am trying to install the SimPy module so that I can use it in IDLE. However, everytime I try to import in IDLE, I got an error. I already tried reinstalling Python and Pip and tried to modify the location of the apps. SimPy can be found in the directory of Python 2.7. I'm using python 3.6.1.

After I correctly installed simpy in the terminal:

pip install simpy
Requirement already satisfied: simpy in /Library/Python/2.7/site-packages

When I put into IDLE:

Import Simpy

I got the error:

    Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    import simpy
ModuleNotFoundError: No module named 'simpy'

How can I solve this?

Since you are using python 3.6.1, you may need to specify the type of python you want to install simpy for. Try running pip3 install simpy to install the simpy module to your python3 library.

Wherever you're running your code, try this

import sys

sys.path
sys.executable

It might be possible you're running python in different environment and the module is installed in different environment.

I had same problem (on Windows) and the root cause in my case was ANTIVIRUS software! It has "Auto-Containment" feature, that wraps running process with some kind of a virtual machine.
Symptoms are the same: pip install <module> works fine in one cmd line window and import <module> fails when executed from another process.

What worked for me is that adding the module location to the sys.path

import sys
sys.path.insert(0, r"/path/to/your/module")

When this happened to me (on macOS), the problem turned out to be that the python installation I specified at the top of my script.py was not the same python installation that conda/pip were using on the command line.

To get the command line and my script to match up, I changed the header in my script.py to just use:

#!python

Then when I ran ./script.py on the command line, everything finally worked.

此命令适用于我的同一问题。

python -m pip install “your library” 

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