Importing python modules in vscode - python

Recently downloaded vscode on macOS, but I seem unable to import any python modules. I've made sure I'm using a python3 interpreter but can't find the problem. For example:
import numpy as np
returns
ModuleNotFoundError: No module named 'numpy'
and similarly for any other modules:
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
I have downloaded homebrew although I don't understand what it is (I'm a physicist not a programmer) and so far spent a few hours trying to figure it out. Any help would be great.

Those two modules are third-part modules that need to be downloaded. The easiest/most common way to download is to use pip, which is a python module that should have come with your python install.
From the command line, run a python3 -m pip install numpy matplotlib. That will call python using the module pip, with the pip command 'install numpy maplotlib' (you can call them one-at-a-time if you like).
Once they are installed, you should be able to import them as you attempted above.

This happened to me before when I tried to download the flask module,all I did was restart my vs-code and everything was working

Related

Do I have to install libraries again on Jupyter if I already have it on python?

I have been using python traditionally(in text editors) and now I am moving on to Jupyter. When I try to import libraries, I get errors.
For importing numpy, I do
Import numpy
but I get error
No module named 'numpy'
but I have this library on my system
So do I have to install numpy on Jupyter again?
Please check have you installed the library in same python repo which your Jupiter is referring. Also please try to create virtual environments it is quite better to maintain for each project.

ModuleNotFoundError from Visual Studio after installing Python modules with "pip" on the command line

I am trying to install modules like tkinter, bs4 and numpy.
I use cmd and pip to install them, and it says that everything is installed fine.
When I am using Visual Studio code it says
ModuleNotFoundError: No module named '....'
How can I find out if Python and the modules are in the same PATH?
Or what can i do to fix that?
I've tried to reinstall Python, but I get the same error.
Is it just the VSC?
File "c:/Users/Γιώργος Μαργα/Desktop/test.py", line 1, in <module>
import numpy
ModuleNotFoundError: No module named 'numpy'
pip install is most likely installing globally into a Python interpreter that is different than the one that you have selected in VS Code.
if vscode not recognize your modules try to reload vscode.
install modules with
python3 -m pip install {new_module}
and then reload your Vs code
make sure to set your Python interpreter within VSCode to the same as the one in your system path pythoninvscode
Ok so i uninstall python and installed it again but this time i checked the box that said add that to PATH or someithng like this.
I also uninstalled python from the windowsstore however when it ry to run a code in VSC it doesnt do anything

"ModuleNotFoundError: No module named 'numpy'" for Python 3.7.3 on Mac

I am following instructions to make a very simple neural network program, and I keep getting an error from my line to import NumPy.
import numpy as np
I always get the following error:
ModuleNotFoundError: No module named 'numpy'
When I use the Mac console and type import numpy, it works fine.
When I am typing the import statement in PyCharm and type it slowly to see what intellisense suggests, it suggests "numbers" or "enum", but NumPy is not there.
When I use the Mac console, I can write import numpy without any problems.
I checked the class-path and it appears to include the Anaconda folders, which is where NumPy is.
Python version: 3.7.3
NumPy version: 1.16.4
macOS v10.14 (Mojave)
If you haven't installed NumPy like,
pip install NumPy
or
pip3 install NumPy
that will most likely be the answer.
If you have I would suggest reinstalling the NumPy package:
pip reinstall numpy
or
pip3 reinstall numpy
Another thing is just try to look at the NumPy page, and search for anything else that might help you!
Python looks for modules in every directory listed in sys.path. The Python binary (and module paths) are almost certainly different for PyCharm and the system installed (Terminal) environments.
You will have to install NumPy within PyCharm. Alternately, you can use sys.path.append(0,'/path/to/numpy') or (in Bash) PYTHONPATH=$PYTHONPATH:/path/to/numpy to temporarily extend the sys.path array to point to another distribution of NumPy on your system.
I tried uninstalling and reinstalling it, but there wasn't any difference.
Atom doesn't have any problem with the import statement. It's only PyCharm, so I will stick to Atom.

ModuleNotFoundError: No module named 'yyy' in Windows Shell

I'm using Python 3.6 on Windows 7.
I have a script that uses standard python packages.
The script run fine from IDLE.
It used to run fine from Windows command too, but not anymore.
I don't know why. It complains about missing package like:
, line 4, in <module>
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
The path looks ok (I've added all path found from IDLE / Path Browser):
PATH=C:\Users\olivier\AppData\Local\Programs\Python\Python36\lib\site-packages;C:\Users\olivier\AppData\Local\Programs\Python\Python36\Lib;C:\Users\olivier\AppData\Local\Programs\Python\Python36\DLLs;C:\Users\olivier\AppData\Local\Programs\Python\Python36\python36.zip;C:\Users\olivier\AppData\Local\Programs\Python\Python36\Scripts\;C:\Users\olivier\AppData\Local\Programs\Python\Python36\;C:\Users\olivier\AppData\Local\GitHubDesktop\bin
Any idea?
Thanks
I had the same problems. Did you try to install it through pip and did you try to install on the strict path by using pip install --target="..." for e.g "pip install --target=C:\U2\UV\python\Lib\site-packages geopy" and pasting it in python console?
Also look at this post: Install a module using pip for specific python version
These two points can help you to solve the problem as per my knowledge.
Are you using two Python versions?
Check the Environmental Variables and if everything is fine there, it's better to uninstall and reinstall it again. use pip for installing and uninstalling

unable to run matplotlib

on 64bit win 7, I installed all of compatible versions of setuptools, numpy, python-dateutil, pytz, pyparsing and six in addition to matplotlib. I did this by downloading source into a folder, and installing from source ... for example,
python setup.py install
finally, I installed python matplotlib by,
cd matplotlib
python setup.py build
python setup.py install
I tested matplotlib by running python from my windows powershell, and typing import pylab I got error:
ImportError: error importing numpy: you should not try to import numpy from its source ...
I found a stackoverflow question that addressed this, leading answer was to change working directory from the directory where numpy lives.
I changed the working directory to another folder in my drive, again ran python from my interpreter, typed import pylab and received this error:
ImportError: NO module named numpy"
I am now at a loss. It either refuses to import numpy, or says it doesn't exist? But it knew it existed earlier?
Ive been looking for a solution for more than three hours now, am stumped. Apologies in advance if this question seems too noob.
finally, I am open to trying a different module if it would be easier. I only want to plot some data.

Categories

Resources