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 that you're running python in one environment and the module is installed in another environment.
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.
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")
This command works for me for the same issue.
python -m pip install “your library”
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.
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.
Related
I've seen similar questions on this site, but none of the solutions have worked. I am using a mac, which gave me some trouble downloading pyaudio. Eventually, I got pyaudio downloaded using pip3 and portaudio installed with homebrew.
I'm coding a virtual assistant, and when I try to use the speech_recognition module, it throws and error telling me that the module cannot find the pyaudio module:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/speech_recognition/__init__.py", line 108, in get_pyaudio
import pyaudio
ModuleNotFoundError: No module named 'pyaudio'
Yet when I try to run the command pip3 install pyaudio, it tells me that pyaudio is already installed:
Requirement already satisfied: pyaudio in /opt/homebrew/lib/python3.9/site-packages (0.2.11)
How do I fix this? Do I need to somehow move my pyaudio install into another directory? I don't know if this is related, but I've also noticed that whenever I run a terminal command beginning with python3 I get the error zsh: killed python3. I've downloaded python3 and that's what I've been using, as well as using pip3 instead of pip.
looks like the interpreter that you are using might be different, it happened with me once but with a different package, I installed it in a different env and tried to run it in the different env. First make sure that you have activated your virtual enviornment, and there do a pip3 list and check if it shows installed, if it is installed, check the interpreter you are using to run the script, if it's from that venv or not.
One thing that should help in any case is to execute export PYTHONPATH=$PYTHONPATH:/opt/homebrew/lib/python3.9/site-packages in the shell before you start the Python interpreter.
I'm running macOS version 11.0.1.
I'm trying to import a module called troposphere
I have Python2.7 as well as Python3.9.1 installed
When I try to import troposphere using Python2.7 like
#!/usr/bin/python
from troposphere import Template
It does work. But when I try to import the same using Python3.9.1 like
#!/usr/bin/python3
from troposphere import Template
It throws error like this
ModuleNotFoundError: No module named 'troposphere'
What should I do? Please help
it is because the python interpreter you use to run your code doesn't have troposphere installed.
Managing multiple Python version on the same computer is tricky, But I will try to explain it.
I assume that you are using python your_script.py to run your code, and pip install troposphere to install package right? But think of this, how does your system know exactly which python you are running and which python to install package? Here's how to check the full path of your python command and pip command.
type python command enter python console
then type this:
import sys
print(sys.executable)
3. navigate up and down little bit, you will find a bin folder include bin/python which is your interpreter and bin/pip which is your pip command. And there's a lib/site-packages folder, this is where third party library been installed to.
4. if you see import error, use the above method to locate the python interpreter and check the site-packages folder, most likely there's no such troposphere folder in it. Then you need to use the full path of the <path-to>/bin/pip to install troposphere. Then your problem is solved.
If you are using home brew or the python installer download from www.python.org, your system probablly already messed up. The recommended way to manage multiple Python version is to use pyenv https://github.com/pyenv/pyenv. It allows you to install any python version and easy to delete them.
Chek if the module was depreciated
I have begun learning to program (in general, and in Python), and I am trying to import a module. I have installed it (using pip install --user requests) and the folder appears in my file explorer. When I try to import requests now inside IDLE, I get a ModuleNotFoundError.
I have tried adding the folder to the PATH environment variable, although I am not sure I understand what this means, but it did not work. What can I do?
If "pip freeze" lists the module, then one option will be to close the idle and type the following at the command prompt/terminal.
python -m idlelib
New IDLE will start and it should be possible to import the module.
That means that the installation you made was not done properly, so when you type in requests to get the module in your script it cannot find it.
Just reinstall it properly with (if the prompt for the python version you want to use is simply python):
python -m pip install requests
EDIT:
Adding to this, based on the comment of #AST :
Indeed, if you get Requirement already satisfied when using the above command, you can first delete requests with the following command, and then try the installation command.
pip uninstall requests
Im trying to use the pyperclip module in the idle python editor. When I try to import I get an error saying:
Traceback (most recent call last):
File "", line 1, in
import pyperclip
ModuleNotFoundError: No module named 'pyperclip'
When I try to pip install pyperclip in terminal, I get the following:
Requirement already satisfied: pyperclip in /anaconda3/lib/python3.7/site-packages (1.7.0)
Im brand new to learning python and developing in general, so sorry if this is an easy solution or covered elsewhere that I could not figure out how to find. Im still learning how to most effectively use python so I'm not sure which editor or system I prefer yet. Is there a way to be able to use the pyperclip module in idle without deleting it from anaconda, or removing anaconda entirely?
Im running python 3.7.2 on a Macbook with macOS Mojave 10.14.3.
Thanks!
In terminal, the following
$ python3 -m pip install pyperclip
or similar should install pyperclip or other modules to the python3 installation, where it can be found when you run IDLE with
$ python3 -m idlelib
I expect the same to be true when you start IDLE from the icon or python launcher, but I don't know what changes Anaconda makes to your system.
I am trying to create a very simple Python 3.6 script. Using MacOS.
For this script I had to install robobrowser, which I installed with easy_install robobrowser. After that I try to import it with the following statements:
import re
from robobrowser import RoboBrowser
However, terminal prompted me with the following (infamous) error:
Traceback (most recent call last):
File "signup.py", line 2, in <module>
from robobrowser import RoboBrowser
ModuleNotFoundError: No module named 'robobrowser'
I have installed Python 3.6. However, in my /Library/Python I only have 2 folders: 2.6 and 2.7. In /Library/Python/site-packages there is a folder named robobrowser-0.5.3-py2.7.egg. Might it have something to do with this?
Sorry for asking a most likely easy question. I can however not seem to figure it out.
Thanks for reading this,
Thijmen.
Probably you are using easy_install for Python2. The best solution is to install pip for Python3 and run pip install robobrowser
This must be because you have multiple versions of Python installed, and when you installed robobrowser, it got installed to a different python version than the one you are trying to use. If you want to use it with Python 3, make your $PATH variable use the Python3's Scripts path instead of the one from Python2. Or a simpler way is to install pip3 on your computer and do sudo pip3 install robobrowser
For reference: changing python path on mac?
You can run the which python, which python3 and which easy_install commands in your terminal to find which versions of python and easy_install are being used by default.