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.
Related
I have problem with importing some modules into python.
First of all, I am on MacBook, it's my first OS X device, so maybe I did something wrong.
I installed conda, created main. Everytime I want to work on my python app, I just open terminal, use command: conda activate main, cd into folder and open in VS code. I used pip3 install opencv-python to download this module, It was completed without errors but when I import everything into python file (cv2, tensorflow, matplotlib.pyplot and numpy) and I just
try to print Hello, I get this error:
Traceback (most recent call last):
File "/Users/zacikm/dev/Python/BC/main.py", line 1, in <module>
import cv2 as cv
ModuleNotFoundError: No module named 'cv2'
Please, help me what can I do to fix this problem. I want to start working on my school project but I'm not able.
Thanks!
Sure.
Picture when I run "pip install opencv-python" under conda env.
Error message what I get after running my code.
Check are you using the right environment after installing the pkg pip install opencv-python.
For example, you are using base python rather the conda one.
Say your conda environment is called test.
You need to run
conda activate test
Then use
pip install opencv-python
to re-install it for this environment. Then you can use cv2 in this test environment.
I had the same problem. I found that the solution was to downgrade the opencv version. In Pycharm, the process is as follows:
In Preferences, go to Python interpreter. You will see the current versions of opencv-contrib-python and opencv-python which may be the same as the latest version.
That is the problem.
Double click on the current version of opencv-contrib-python to open this screen:
Check the specify version checkbox and find version 4.1.2.30. Then click Install Package and wait a few seconds to get a message that package was successfully installed. Press OK and you should see opencv-conbtrib-python downgraded to the appropriate version.
After step 3, opencv-python may have also downgraded to the appropriate version 4.2.0.34. If it hasn't, follow the same process to downgrade opencv-python to 4.2.0.34. At the end, your python interpreter screen should look like this:
That should do it. Test it to make sure it works.
Relatively new to Python I've created a project using Pipenv that uses the xmltodict module. I've looked at some similar questions but can't find exactly what I need to do.
I've used pipenv to install the xmltodict module but I'm still getting the following error:
Traceback (most recent call last):
File "./storagereport.py", line 12, in <module>
import xmltodict
ImportError: No module named 'xmltodict'
Pipenv shows that the module is installed:
$ pipenv graph
xmltodict==0.12.0
Can anyone help?
You might be running Python from another version , which is usually the default version that is installed. If that's the case, in your virtual environment you will find python.exe and pip.exe you have to run pip from the virtual environment
Try with following command:
sudo pip install xmltodict
or
sudo pip install xmltodict --upgrade
I run into this regularly, I believe because I'm behind a firewall. I download the package that I need to my computer and then I install it. If that doesn't work, I navigate to the download folder where it is and install it from there. You can download this package here:
https://pypi.org/project/xmltodict/
I downloaded the file from here- https://pypi.org/project/xmltodict/#files and after extraction placed the .py file in the directory where I was importing xmltodict. Then it worked fine.
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.
I am new to installing new python modules.
I installed tweepy using pip install tweepy. The installation was successful and 2 folders tweepy & tweepy-3.3.0.dist-info are created in the Lib/site-packages, hence I assumed all should be fine.
However, when I went to the IDE and import tweepy. It is unable to detect the module:
>>> import tweepy
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
ImportError: No module named tweepy
What is wrong?
I am running python 2.7.5.
[Update 1] I am using windows 7.
I first installed pip using another forum's suggestion (How do I install pip on Windows?). basically saving the get-pip.py script and double clicking it (unable to get "python get-pip.py" to work in cmd prompt as suggested). Then, I went to cmd and nagivated to C:/Python27/Scripts and type in pip install tweepy. I remembered seeing the result as a successful installation.
[Update 2] Using a file with import tweepy and running it, I have a similar error.
Traceback (most recent call last):
File "C:\Python27\ArcGIS10.2\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
exec codeObject in __main__.__dict__
File "C:\Users\xxxx\Desktop\Script1.py", line 2, in <module>
from tweepy import Stream
ImportError: No module named tweepy
[Update 3] Typed "pip freeze" in cmd. It does show tweepy=3.3.0
C:\Python27\Scripts>pip freeze
oauthlib==0.7.2
requests==2.7.0
requests-oauthlib==0.5.0
six==1.9.0
tweepy==3.3.0
wheel==0.24.0
[Answer] Thanks for all the help guys, especially Cleb & omri_saadon suggestion that there might be something wrong with the file path.
I just realised that my GIS software, ArcGIS by default installed another Python into the Python27 folder, and everything is taken from that folder, C:\Python27\ArcGIS10.2, instead of C:\Python27. After I install tweepy from C:\Python27\ArcGIS10.2\Scripts, everything works well.
Try to pip uninstall tweepy
and then again pip install tweepy
Make sure you don't have several interpreters on your computer, if you have several, make sure that your pycharm(or any other editor you use) is configured with the same interpreter where you installed tweepy.
I tried this command py -m pip install tweepy and worked for me
If you are using Anaconda
conda install -c conda-forge tweepy
you may also use
easy_install tweepy
If you are using ubuntu try: sudo apt install python-pip
and then run: python3 -m pip install tweepy
I hope that helps!
If you are using conda enviroments and jupyter notebooks, you could try to install it from the notebook and restart the kernel:
!conda install -c conda-forge tweepy
The problem is that , tweepy in getting installed in the native python environment, i.e you might be able to import it in cmdline but must be getting error in jupyter notebook.
If this is the case, then you might need to install it with conda environment , with conda install tweepy. But if in this case also if you fail to install it due to conflicts errors thrown by conda do the following.....
Copy all the required tweepy pip files from the python environment, which you can find by running the pip install tweepy cmd which shows that the required package is already satisfied in a particular path.
You might be required to copy tweepy, requests, requests_oauthlib, oauthlib.
Paste the copied files into site-packages inside of Anaconda environment folder.
This solved the problem for me , hope it solves for you too.
If multiple versions of python are installed on the computer, you need to make sure under which version the package has been installed into. I have two versions of python installed on my mac, both python2 and python3 under /usr/local/lib path.
pipinstall tweepy only installs the package into python2.7/site-packages, while VSCode complies python3. Run pip3install tweepy to get the package under python3.7/site-packages so the module can be recognized by the compiler.
I had the same issue where after installing/ uninstalling via pip it still did not work. As a last ditch effort I actually moved the 'tweepy' folder in the '...Lib > site-packages' back to the main Python directory and 'import tweepy' then worked. No idea why this worked, but it did for me... Good luck!
I tried this, I was having the same error, but the thing that I did was, first installing the package using pip command, then spot the path where it got stored, then using os module change the directory to where the packages got stored, and then import it, it will work..
Very common error wherever your computer have different python environments in pycharm. Your computer may have different python interpreters as you install pip several times. Try to config the exact python interpreter using the following steps. PyCharm, Settings -> Project Interpreter -> This will show the installed package list and dedicated interpreter at the top right-hand side. Try your right interpreter within the dropdown.
If you are using Jupyter Notebook, just run the command below in the cell of the notebook.
!pip install tweepy
If you are using Jupyter notebook on Anaconda try:
sudo conda install tweepy
This worked for me on OSX.
The same for me, typing direct in the console import tweepy it works, but when I tried to run from the script it says 'No module named 'tweepy'' i tried to uninstall and install again but the solution was more simple,
instead of run like
C:\script.py
I run
C:\python script.py
It works, Python version is 3.6.2 tweepy version is 3.5.0
If you are using Jupyter Notebook, the only thing that worked for me was to first install Jupyter again
pip install jupyter
and then install tweepy
pip install tweepy
I installed PyBrain via PyCharm and when I try to compile I get the following error:
Traceback (most recent call last):
File "C:/Users/Marcus/PycharmProjects/ANN/ann.py", line 2, in <module>
from pybrain.tools.shortcuts import buildNetwork
File "C:\Python34\lib\site-packages\pybrain\__init__.py", line 1, in <module>
from structure.__init__ import *
ImportError: No module named 'structure'
However, in the folder site-packages\pybrain\ there's a folder named 'structure' with (what I assume is) what pybrain is asking for.
I'm pretty new to Python so I'm not completely used to this installing packages thing. Is it something that I missed? I have tried to search for a package named "structure" in the PyCharm package installer but there is none (only a 'structures').
Thanks in advance
EDIT: A comment asked me to further explain how I installed the package. In PyCharm, I went to project settings -> project interpreter -> search for "pybrain"
I was having the same problem and tried all the suggestions mentioned here. Finally I realized that the version that was installing was 0.3.1, and it is not compatible with Python 3. So I deleted that version and then ran
!pip install https://github.com/pybrain/pybrain/archive/0.3.3.zip(from Spyder ipython console). This finally worked.
I encountered the same problem.
I am working on Windows 8, 64 bit machine, with WinPython.
As every newbie would do. I install pip and then installed pybrain (or PyBrain, doesn't make difference).
After I tried to see if its working like this :
import pybrain
I got an error saying :
There is no module named "Structures".
When I checked the site-packages, it was there.
I tried the following approaches :
I tried reinstalling Structures.
I tried using pip3 instead of pip.
I tried pip3 install pybrain --upgrade
I downloaded the .zip file of the entire project from github here and after unzipping it, went inside it from cmd and did python setup.py install.
The 4th approach worked like a charm.
Cheers.
What I have done as following and it works. (windows 7, anaconda3 installed)
Download ZIP file from https://github.com/pybrain/pybrain
Extract the zip file and try python setup.py install
Open anaconda command and run conda update conda
This worked for me: pip3 install https://github.com/pybrain/pybrain/archive/0.3.3.zip
In my case was pip3, but it could be pip
I would use pip (installed with 3.4) to install packages for 3.4+. I used pip install pybrain (or maybe ... PyBrain) last summer (for someone else) and the install worked with no problem.
What is a problem is that PyBrain is a 2.x package. Fortunately, most of the incompatibilities are in the test suite (and those mostly due to using doctests). The user I installed it for ran into a few easily fixed syntax errors and is still using PyBrain for a research project.