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.
As the Anaconda Distribution of Spyder has some typing latency issues on macOS Big Sur, I've gone ahead and downloaded the standalone distribution. However, when trying to install packages with pip I get the error message:
pip install numpy
/Applications/Spyder.app/Contents/MacOS/python: No module named pip
Note: you may need to restart the kernel to use updated packages.
(I know that NumPy is already installed - this just serves as an example). I have Anaconda installed, and there pip works fine. How do I install it for the specific Standalone Distribution?
I solved this problem using the Command Prompt and typing pip install -U spyder. If you don't have the "standalone version" of Python, just install it to have access to this command.
After that, you can simply open Spyder typing in the Command Prompt spyder.
I have installed dlib using Anaconda 3 prompt.
It has shown me that it got installed successfully. I checked through command import dlib it did not give me any error even I checked the version also it came up with 19.9.0.
But when I open my program in IDLE and run the program its showing me error
import dlib ModuleNotFoundError: No module named 'dlib'
Even from command prompt, I am getting same error.
What is the issue? I am using Python 3.6.
Installation process of dlib using anaconda3:
You have installed the package in different version of python and importing the package in other version of the python.
Package is installed. in virtual environment(3.6.8) and is being imported in standard system python (3.6.0).
So either you need to use this virtual environment for your application otherwise you will need to install the package into global system python.
Extending #Rohit's answer:
As you have installed dlib in Anaconda, you need to run the program using Anaconda prompt.
By default, IDLE and python command in command prompt use Python that is installed system wide (which is Python 3.6.0 in your case).
But to use dlib which is installed in Anaconda's virtual environment (env_dlib) you need to do:
Open Anaconda prompt.
Activate env_dlib environment: activate env_dlib
Run the Python file which uses dlib package: python FILENAME
I have recently installed Anaconda with Python 3.5 and all the rest. I come from R where I am used to install packages dynamically. I am trying to install a module called scitools through jupyter notebook. I would like to recreate this in jupyter. However, I don't know how to dynamically install packages (if it's possible). I would greatly appreciate your help. Thank you!
EDIT: I am trying to use conda as recommended by the community, but it's not working. I am using mac OSX
Check Jake Vander Plus Blog here to learn how to install a package with pip from Jupyter Notebook.
# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install numpy
So if you have already done the install with anaconda, you may already have the module installed. In that case in your jupyter notebook after you have activated your kernel, you just need to make sure you execute the import statement.
import scitools
If you haven't installed that module yet, you can install it one of two ways. Both work from your command line or terminal.
pip install scitools
or since you have Anaconda
conda install scitools
and that should do it. Your import statement in your notebook when executed should correctly locate and enable the use of that module.
I had the same issue. It turns out if you open an anaconda window, which in Windows is accessible under the Anaconda drop down, it points to the correct location to install (or update) using pip.
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