Failed to import numpy python module in PyCharm - python

I am learning Python in my free time. I am pretty new. I use PyCharm for IDE.
When I:
import numpy as np
it says:
ModuleNotFoundError: No module named 'numpy'
When I:
pip3 install numpy
it says:
Requirement already satisfied: numpy in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (1.15.4)
When I go to PyCharm - base interpreter is set to:
/Library/Frameworks/Python.framework/Version/3.7/bin/python3
The only suspicious thing I find is that Location of environment in PyCharm is set /Users/XXX/PycharmProjects/MachineLearning/venv
I read a little bit about environments and it makes logic if I have installed numpy in one env and use another in the IDE, but not sure how to check this.
Help is appreciated. Thanks.

It was really because of the virtual environment. I installed numpty in the specified in my PyCharm project virtual environment and it worked. I did this by opening PyCharm -> Preferences -> Project Interpreter and I saw that for my project the following virtual env is configured:
I activated it by source /Users/XXX/PycharmProjects/MachineLearning/venv/bin/activate
and then pip3 install numpy
Another option is to change the interpreter to some containing all packages installed.

Related

I have installed Numpy but PyCharm can't find the module

When I run import numpy as np
I get ModuleNotFoundError: No module named 'numpy'
I have tried it in the project I always used, I have tried it in a new project where Conda is the environment used but I always get this error. I am clueless here.
When I type in the Terminal of my Macbook pip3 install numpy I get the answer that I already have numpy Requirement already satisfied: numpy in /opt/anaconda3/lib/python3.9/site-packages (1.21.5)
Often, many IDEs (like Spyder, Jupyter Notebook, or PyCharm) installs their own virtual environment of python to keep things easy and simple for them from your global python.
even if you have a package installed in your global python, you might not able to use it in your virtual environment since it would have separate package management.
So the solution is to install the package using the IDEs.
In your case you can do it by using their terminal or using the red bulb (which will appear on the top of your pakage)

Issue with Anaconda package manager - library installed, but not found in Spyder

I installed cairo using Anaconda Navigator (in case it's important, cairo is also installed in the other two environments: miniconda3 and spyder-env):
I launch Spyder from Anaconda Navigator, and try to import cairo, and get an error saying:
ModuleNotFoundError: No module named 'cairo'
Spyder seems to be using the correct python environment. If I run `conda list cairo', I get the following output:
What am I doing wrong?
I had problem similar to this with VaderSentiment analysis library. Jupyter notebook couldn't find it although it was installed. Either you can use a more stable Python version such as Python 3.7 for compatibility or you can use importlib.
conda install python=3.7
I solved it using importlib This does not answer your question "what am i doing wrong", but it solved the problem in my case. Just locate cairo.py in your Anaconda folder whatever the environment is. You can make necessary adjustments. I hope this helps if you have emergency to use that package.
import importlib.util
import sys
spec = importlib.util.spec_from_file_location("vaderSentiment", r"C:\Users\matt\Anaconda3\envs\sentiment\Lib\site-packages\vaderSentiment\vaderSentiment.py")
foo = importlib.util.module_from_spec(spec)
sys.modules["vaderSentiment"] = foo
spec.loader.exec_module(foo)

I get an ImportError: No module named 'numpy' when trying to use numpy in PyCarm, but it works fine in the interactive console

I'm already installed numpy and it works in cmd.
my Python version is 3.7.2 and numpy version is 1.16.0
When I use numpy in windows cmd, It works.
import numpy is working well in the python interactive console.
But in pyCharm, it doesn't work and errors with No module named 'numpy'.
How can I solve it?
You probably arent using the same python installation in pycharm and in your console. Did you double-check in project settings ?
If you just want to install numpy, you can create a requirements.txt file and add numpy in it, pycharm will suggest to install it if not already done.
Alternatively, you could use a venv

Downloaded Pandas, but getting error when importing into Pycharm

I downloaded the pandas package to my computer using the pip install. When I try to import pandas as pd into Pycharm I get the following error message:
ModuleNotFoundError: No module named 'pandas'
I know I have downloaded the package, but how do I get Pycharm to recognize that I have downloaded the package?
You almost certainly don't have your interpreter set correctly.
Go to preferences -> project -> project interpreter and make sure that the version of Python matches the environment where you did you pip install or conda install.
Also, if you aren't sure which Python you're using you can always run which python.

Conda openpxyl install results in No module named 'openpyxl'

I installed several conda environments with different Python versions.
After activating my Python 3.5 environment I have installed openpxyl via the line given here: https://anaconda.org/anaconda/openpyxl
However, when I try to import I get
ImportError: No module named 'openpxyl'
When I type conda list I do see
openpyxl 2.4.7 py35_0 anaconda
in the list.
(code to import is just import openpyxl or from openpyxl import *)
Any suggestions? Thanks!
You can try deleting all openpyxl material then reinstall it using pip.
that's how i solved my problem at least.
Even I faced the Same issue. This might Help you. If we have given python path in the windows environment variables which is present before we installed anaconda. We can test it by using
python --version
It will give you the version if the path is already present as
Python 3.6.5
Please remove this path of python which is already mentioned.
Then give the path of the python which is is anaconda directory. Normally it will in the path
C:\Users\lenovo\Anaconda3\
Just add this path to environment variables and again check for the python version
that might give you the following result
Python 3.6.5 :: Anaconda, Inc.
then it is confirmed that you are using the python which is downloaded using anaconda package manager.
Now you use the conda modules anywhere.

Categories