Python can't find numpy in Idle - python

I have an odd problem. I Installed Python 2,7 and afterwards installed Anaconda. If I use the terminal and type "python" followed by "import numpy" I everything is fine, no error.
However if I try to import numpy in the IDLE I get this:
"ImportError: No module named numpy"
Why is this? I thought the numpy was installed on the computer once and for all when I installed Anaconda.

When u install Anaconda it installs Python and other packages and might add Python to the PATH. Hence when you type python it opens anaconda's interpreter which has necessary packages. But you are opening IDLE of your previous python interpreter which doesn't have numpy.

Related

How to get python packages installed for 32 bit before but works on 64bit as well in Visual Code? E.g. Pytorch

I use
(1) Windows 11,
(2) Python 3.7.8 for 64bit ;
Python 3.8.3 for 32bit
(3) Visual Studio Code.
I noticed that all my python packages are installed on 32Bit, is there any way to get my packages works on 64bit as well? Because I wish to use Pytorch, however, it only works on 64bit
I tried to install packages again, but it installed for my 32 bit? So it cannot install again?
I checked my system path but I have no idea how to do with path for my packages?
I also installed PyTorch in Visual code, but it does not appear installed in my python environment...Why?
I tried to install PyTorch by pip and it gives me error as below:
Updates: ------------------------------------------------
I tried: Ctrl+Shift+P, select that 64bit python
Then, in the terminal I tried to install packages, it still shows that my package is already installed...
You have selected Python3.7.8(64) in the jupyter notebook, while you have installed the python modules in the Python3.8.3(32) environment. So it will prompt No module named 'pandas'.
And looks like torch has no 32bit version, if you want to use it, you need to select Python3.7.8(64).
So, you can activate the terminal first through open a python file and then clicking the python interpreter on the bottom-right of the VSCode or choosing Python: Select Python interpreter in the command palette directly.
Then take the shortcut of Ctrl+Shift+` to create a new terminal with the activated python environment. After this, you can install the modules in the right place.
You can refer to the official docs for more detail.

Why do I receive a "no module named scipy" error even after I have installed the module via pip?

I am using Python 3.9 on Windows 10 which I downloaded directly from the Microsoft Store.
I tried running a script in PowerShell: Bash *.sh
This script is supposed to tell my computer to execute a .py script which uses scipy.io and many other modules.
Then I received this error:
ModuleNotFoundError: No module named 'scipy'
My strategy was to make sure pip was up to date, then use it to install the desired packages, then run some commands to see if the packages were installed.
I ran this command to update pip:
python3 -m pip install --upgrade pip
I ran this command to get some modules:
python -m pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose
I also tried this command just in case:
pip install scipy
and got the result:
Requirement already satisfied ...
I ran the command pip list to make sure scipy was in the list (and it was there).
Then I ran the command python and my prompt changed to ">>>" and entered import scipy and did not receive any errors.
I am very confused as to how I have scipy installed yet have my script tell me it isn't there. Please help!
From what you have posted it looks like you have more than one python environment path in your system, because of which when you are installing these libraries they are installed at certain location while when you run the bash script it is using some other python location.
Try using these commands in both your terminal (cmd in windows) as well as in you bash script:
import sys
print(sys.path)
This will give you the python environment path (location where your python libraries are present), then compare both the path you get from your terminal as well as bash. Add the path you got from the terminal to your global environment in order to make sure the same python version is used everywhere.
You can also refer to this: Python modules not found over terminal but on python shell, Linux
I had the same issue. You might have multiple versions of python and you only installed scipy on the one you are not using
OR
you are using an IDE which has the option to use packages you install that are not by default in python. Pycharm has that. When you make a new project, it has a tick option saying "Inherit global site-packages" which means it will use additional packages you have installed any.

pandas work on jupyter but not recognized in cmd or anaconda prompt

I want to run a script in .py with cmd or anaconda prompt but says pandas can't be recognized.
'pandas' in sys.modules
False
the version of python is the correct where these libraries are installed. The correct path is somehow not in connection with the cmd and all the libraries installed with the anaconda are not seen. How to make it work without installing all the modules again?
The solution was to write the word python too.
python hx.py
now it runs if typed in the anaconda prompt.
All nice.
Usually this is fixed with a simple from command line:
python -m pip install pandas
if this doesn't help, I will suggest you to remove all the python packages and do an anaconda reinstall on your system

Python Anaconda - no module named numpy

I recently installed Anaconda on Arch Linux from the Arch repositories. By default, it was set to Python3, whereas I would like to use Python2.7. I followed the Anaconda documentation to create a new Python2 environment. Upon running my Python script which uses Numpy, I got the error No module named NumPy. I found this rather strange, as one of the major points of using Anaconda is easy installation of the NumPy/SciPy stack...
Nevertheless, I ran conda install numpy and it installed. Now, I still cannot import numpy, but when I run conda install numpy it says it is already installed. What gives?
Output of which conda: /opt/anaconda/envs/python2/bin/conda
Output of which python: /opt/anaconda/envs/python2/bin/python
The anaconda package in the AUR is broken. If anyone encounters this, simply install anaconda from their website. The AUR attempts to do a system-wide install, which gets rather screwy with the path.

ImportError: No module named ... after spyder install

Anaconda Spyder is supposed to include numpy, scipy etc with the installation. Someone has installed Spyder for me on Windows 7 but if I try to import numpy or scipy , I get this error:
import numpy as np
ImportError: No module named numpy
I also can't run "conda" on the console.
What's wrong? What should I do to fix this? I tried adding PYTHONPATH in environment variables but no difference.
How can I check if they're even installed? I searched for NumPy in the computer, I only found the following:
It sounds like someone installed just spyder, not Anaconda, which is a separate thing (Anaconda is a collection of several Python packages, including Spyder, NumPy, and SciPy). Try downloading and installing Anaconda and using the Spyder that comes with that.
The thing is you have to install python 2.7. Surely you have a different python installed. If you download and install Python 2.7 this should works. Other thing you can do is search for the Anaconda Spyder version that support the Python you have installed.
It's probably that your the python core version of your spyder environment is different from the conda python version.
Python core version of your spyder environment
Conda python version
So you should make them of the same version then the problem will be solved.

Categories