26

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?

Robert
  • 263
  • 1
  • 3
  • 4
  • 1
    Have you checked your environment's PYTHONPATH variable? https://stackoverflow.com/questions/19917492/how-to-use-pythonpath – ginginsha Jun 13 '17 at 18:12
  • IDLE is almost never relevant to import errors, and it is not in this case. If you ran interactive 3.6 from the console and entered `import simpy` as you did, you would see the same error. – Terry Jan Reedy Jun 14 '17 at 02:47

8 Answers8

15

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.

cosinepenguin
  • 1,545
  • 1
  • 12
  • 21
12

Wherever you're running your code, try this

import sys

sys.path
sys.executable

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

Nadjib Mami
  • 5,736
  • 9
  • 37
  • 49
alok.m
  • 148
  • 1
  • 6
3

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")
3

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.

Robin Stewart
  • 3,147
  • 20
  • 29
  • 2
    This led me to try `which python3`, which revealed that on the command line I was using `/usr/local/bin/python3`, which I must have set up at some point (and then forgot about) so as not to conflict with the default installation in Monterrey. The script was using `/usr/bin/python3`. Thanks for the clue! – Turnsole Jul 19 '22 at 13:20
2

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.

Dima G
  • 1,945
  • 18
  • 22
2

This command works for me for the same issue.

python -m pip install “your library” 
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-ask). – Community Sep 20 '21 at 17:02
  • Not enough detail. Sounds like you're inside the venv when running this, so the Python version would already be correct. – ChrisN Oct 20 '22 at 18:36
1

I wrote a package by myself and I thought the __init__.py could be ignored, then I encountered this issue. when I added an empty __init__.py to my package, this issue was fixed.

jianjunwu
  • 21
  • 5
0

Do not have a file called simpy.py in the current working directory, as python will try to load this file instead of the module that you want.

This may cause the problem described in the title of this question.

Bálint Sass
  • 310
  • 3
  • 11