I have a code in python which uses numpy and when I try to run it on ubuntu bash shell in windows 10 there is an error like this:
Traceback (most recent call last):
File "kepler.py", line 2, in <module>
import numpy as np
ImportError: No module named 'numpy'
while numpy has already been installed in my windows and when I try the same code via windows command prompt it works well. I have tried to install numpy via ubuntu bash shell with this command
pip install numpy --user
The installation finishes successfully but when running the code "kepler.py" that error message shows up again. Then I type again
pip install numpy --user
but I get this message:
Requirement already satisfied: numpy in ./.local/lib/python3.6/site-packages (1.16.3)
Related
I was trying to use numpy in Jupyter Notebook in a Python3 virtual environment, but the encountered an error.
In terminal, I did:
$ python3 -m venv py3env
$ source py3env/bin/activate
(py3env)$ jupyter notebook
And on the Jupyter page, I created a new notebook and executed the followings
!pip install numpy
import numpy as np
And the resulting output is this:
Requirement already satisfied: numpy in /Users/MyName/py3env/lib/python3.9/site-packages (1.20.2)
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-4-d83b6b4f94f9> in <module>
1 get_ipython().system('pip install numpy')
----> 2 import numpy as np
ModuleNotFoundError: No module named 'numpy'
The package is already installed but still cannot be found...?
Is there a way to fix this issue?
You may be using pip from a different python installation.
To install with the same python executable as your jupyter kernel, in one cell run:
import sys
Then in another cell run:
!{sys.executable} -m pip install numpy
It would appear you are trying to call a dependency you installed on a virtual environment, attempt to reinstall numpy on jupyter, then try again.
I have Python 3.7.3 installed and installed numpy, scipy via pip (cmd -> python -m pip install --user numpy scipy) and am able to import numpy, scipy if I use an admin command prompt to import both numpy and scipy. However, if I don't use an admin cmd prompt, or try to import scipy from the Python shell, I receive traceback errors like the following:
>>> import numpy
>>> import scipy
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
import scipy
ModuleNotFoundError: No module named 'scipy'
Does this traceback error come from not installing scipy in a certain way? Thanks for the help in advance.
When doing checking pip and python versions in cmd, here's my output:
pip --version
pip 19.1 from c:\program files\python37\lib\site-packages\pip (python 3.7)
python --version
Python 3.7.3
Add the location of your python scripts to the Path in Environment Variables.
C:\Users\User_Name\AppData\Roaming\Python\Python37\Scripts
You mentioned that you've already installed the packages. And the packages are stored in the site-packages file inside Python37 folder. So the error must be because you didn't add these to the path.
I'm trying to run python script from terminal, but it's giving me error.
I already installed from linux terminal library sympy 'pip install sympy'. But still it doesn't work
This error i get when trying to run python script file.
Traceback (most recent call last):
File "script.py", line 2, in <module>
from sympy import symbols, diff
ModuleNotFoundError: No module named 'sympy'
Are you using two versions of Python?
python3.x uses pip3, and python2.x uses pip
1) Install pip3 on your system.
sudo apt install python3-pip
2) Install sympy by running
pip3 install sympy
3) Open python3 shell (run "python3" on your terminal) and import the necessary libraries
from sympy import symbols, diff
Um... I wanted to import matplotlib in Python IDLE, but it said
>>> import matplotlib
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import matplotlib
ModuleNotFoundError: No module named 'matplotlib'
I've already tried pip thing and the conda thing in terminal.
It said
# All requested packages already installed.
# packages in environment at /Users/Dan/anaconda:
Then! what's the problem here?
You may have installed Matplotlib to Python 2.7 and not Python 3.6. To install it to Python3 you need to use pip3:
pip3 install matplotlib
Then open python3.6 from your terminal (not idle) and try importing matplotlib from there. This way you can use any text editor you wish, and run your code from the terminal.
I had the same issue using the same command in IDLE. I just figured it out. go to your terminal and enter:
pip3.6 install matplotlib
I was using pip3 instead of pip3.6
I have extracted ipython-1.1.0.tar.gz in /usr/lib/ipython-1.1.0 and have run the following commands to finish the build and installation:
root#my-laptop:/usr/lib/ipython-1.1.0# python setup.py build
root#my-laptop:/usr/lib/ipython-1.1.0# python setup.py install
I am using Python 2.6 and is installed under /usr/bin/python2.6 and have my additional packages under /usr/lib/python2.6/site-packages/
Now, when I am trying to start ipython notebook from shell command, I am getting the following ImportError message:
root#my-laptop:/usr/lib/ipython-1.1.0# ipython notebook
Traceback (most recent call last):
File "/usr/local/bin/ipython", line 5, in <module>
from IPython import start_ipython
ImportError: cannot import name start_ipython
When I tried to start the IPython instance as mentioned in README.rst file, I got the following message:
root#my-laptop:/usr/lib/ipython-1.1.0# python -m IPython
/usr/bin/python: IPython is a package and cannot be directly executed
I tried easy_install and pip install
root#my-laptop:/usr/lib/ipython-1.1.0# easy_install ipython
Searching for ipython
Best match: ipython 1.1.0
Adding ipython 1.1.0 to easy-install.pth file
Using /usr/local/lib/python2.6/dist-packages
Processing dependencies for ipython
root#my-laptop:/usr/lib/ipython-1.1.0# pip install ipython
Requirement already satisfied: ipython in /usr/lib/pymodules/python2.6
Installing collected packages: ipython
Successfully installed ipython
But the ImportError problem still remains unresolved. This is not allowing to open the interactive Python.
I found some solution in the below link, but not sure about it:
https://trac.macports.org/ticket/40119
I just ran into this problem as well. Are we sure the IPython API didn't change? I got something that looks right working with:
import IPython
IPython.Shell.start()
edit:
ok, nvmind. There was also another program I installed at the same time that decided to change PYTHONPATH.
This worked for me:
import IPython
IPython.start_ipython()