I am trying to import the module mtcnn in VSCode.
I have run the following commands in the terminal:
pip3 install MTCNN
and
python3.8 -m pip install mtcnn
Which downloads MTCNN
Terminal showing its already installed
But when I try run my python file in VSCode, I run into this error:
Error
I am using python version 3.8.5 in VSCode. There is no red line error under the import line in VSCode so I'm confused why it's not working.
Open an integrated terminal in VS Code, run python --version to check if it's as the same as the one you selected for python interpreter, which is shown in status bar.
Run pip show mtcnn. If you get detailed information like name, version and location, reload window should solve your question.
If you get WARNING: Package(s) not found: mtcnn, it means no such module in your current selected environment, install it.
Besides, to avoid messing up the global python environment, you may create a virtual environment. See Create a Virtual Environment.
Related
The requirements for the code to run is
Python 2.7
TensorFlow 1.n
SciPy & NumPy
I have python 2.7.8 by checking python --version. Installing them on python website also lead to a message saying there is no software to install so I assumed that I already have python 2.7x
For tensorflow I have install it using pip3 install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.0.0-py3-none-any.whl
and for Scipy and numpy i did brew install numpy scipy ipython jupyter
I have a python env setup call mypython.
Using pip list I have the following modules install as shown in the image.
But still VScode prompt an error and say that No module named 'tensorflow'when i run the code file.
How do I solve this?
enter image description here
Install Python extension instead of MagicPython;
You're using mypython in integrated Terminal but in left bottom corner, you select the global one,which is python3.10.1 as interpreter. Open Command Palette and choose Python: Select Interpreter, select mypython then reload window,the error should go away
Think you might be using the wrong pip. Could you run following in your terminal, with your venv activated.
$ pip --version
$ pip3 --version
Try installing with pip instead of pip3
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.
I'm currently working in VS code; wanting to interact with an .mdb file.
File "d:/UDtools/CostEstimator/vsWorkspace/pyOdbcv1.py", line 1, in <module>
import pyodbc
ModuleNotFoundError: No module named 'pyodbc'
pip installed in cmd, pip installed again in VS terminal: Requirement already satisfied.
I'm a bit new to this.
The reason is that the module "pyodbc" you installed is not installed in the VSCode environment you are currently using.
Check the installation tool "pip". When we use 'pip' to install a module, the source of 'pip' determines where the module exists. Use "pip --version" to check if it comes from the current environment:
(If not, please use the shortcut key Ctrl+Shift+` to open a new VSCode terminal, VSCode will automatically enter the current environment.)
Install the module. Use 'pip' to install the module in the currently selected environment: "pip install pyodbc" or "pip3 install pyodbc"
Check the installation package. "pip list":
Run:
More: Environment in VSCode.
If you are using the python extension to run you files. Then you are using python in a virtual envirnment to run python and not the system python. so even if you installed a package, as long as you did not install it in the venv python vs code won't find it.
To test this run your .py file from the command line and see if you get the same error.
if you don't then reconfigure you python interpreter in vs code or install the package in the vnev.
I'm using virtualenvwrapper to manage a project where I'm just running this for now
import apache_beam as beam
from apache_beam.options.pipeline_options import PipelineOptions
with beam.Pipeline(options=PipelineOptions()) as p:
pass
This is returning the following error
Traceback (most recent call last):
File "path/to/pipeline.py", line 1, in <module>
import apache_beam as beam
ModuleNotFoundError: No module named 'apache_beam'
I have run pip install apache-beam. Running pip list returns
➜ pip list
Package Version
------------------------------ ---------
apache-beam 2.23.0
avro-python3 1.9.2.1
...
I'll add the following outputs as suggested in a similar question.
pip freeze
➜ pip freeze
apache-beam==2.23.0
avro-python3==1.9.2.1
...
pip -V
➜ pip -V
pip 20.2.2 from /Users/miguel/.virtualenvs/myenv/lib/python3.7/site-packages/pip (python 3.7)
python -V
➜ python -V
Python 3.7.3
which python
➜ which python
/Users/miguel/.virtualenvs/myenv/bin/python
which pip
➜ which pip
/Users/miguel/.virtualenvs/myenv/bin/pip
I don't know if this is relevant but I'm using VSCode and I have selected my python interpreter according to VSCode instructions here. Additionally, I installed python following the instructions here.
Any idea why this is happening?
First test if your installed Python modules work outside of an ide like VSCode.
We can do this by opening the terminal/command prompt and activating our virtual enviornment. In this case, as you're using virtualenvwrapper you need to use the command:
workon myenv
Documentation for the virtualenvwrapper can be found here. Once activated, we can open the Python interpreter in our terminal by using the command:
python
Once running, try and import apache_beam as before using:
import apache_beam as beam
If this works we now know it's a virtual environment set up issue using VSCode. For setting up Virtual Environments for Python in VSCode, use the official documentation Using Python environments in VS Code. This should allow you to specify the virtual environment.
If this fails to work, another option is to create a new virtual environment in VSCode and install your modules. Installing modules to a environment in VSCode can be found in the VSCode instructions you linked to in your post.
I tried to re-create your issue as above using the following:
Python 3.7.7
VSCode 1.48.0
apache-beam 2.23.0
My virtual environment was named 'stack'. Once I had created it the only module I installed was apache-beam using:
pip install apache-beam
When creating the project I made the directory and launched via terminal using:
- mkdir hello
- cd hello
- code .
And then added the Python interpreter via the command:
Python: Select Interpreter
One additional step I needed (as I usually use PyCharm for Python) was to install:
Shell Command: Install 'code' command in PATH** command.
To allow the launch of code via terminal. Below is a screenshot of the project after following these steps and running the same commands as posted in your question for reference.
My .vscode/settings.json is as follows:
{
"python.pythonPath": "/Users/robertyoung/envs/stack/bin/python"
}
I am writing some basic code in visual studio code and I am trying to use pynput, but when I import the module despite the fact that I installed it using pip it gives me this error:
ModuleNotFoundError: No module named 'pynput'
I have tried to install it using pip3, but it doesn't work
I have also tried to install it using the path interpreter, but it still doesn't work
This is the code:
from pynput.mouse import Button, Controller
mouse = Controller()
# Read pointer position
print('The current pointer position is {0}'.format(
mouse.position))
Strange thing is that this code works in sublime text 3,
but doesn't work in neither visual studio code nor cmd.
Thank you in advance.
Your package associations may be incorrect.
First, see where your IDE is running python. it should be something like C:\programData\Python
Reinstalling the python interpreter may fix this. Or try upgrading the pip, which uninstalls the old one, and pulls down the new one from the cloud. Open a CMD windows, and type the following command:
python -m pip install --upgrade pip --user
This will give you a fresh pip installation. Then try "pip install pynput"
If this does not solve the issue, uninstall your current interpreter, then go to python.org, and download and install the latest interpreter. Upgrade the pip.
if you are trying to run it from within the IDE, check the paths in witch it calls the python interpreter.
if it's pointing to any conda installation try conda install pynput instead
Most IDEs create an "interpreter" for your project, which in python-speak means that the IDE set up a "virtual environment" for you. Virtual environments are great for managing dependencies across different projects. For example if you need one version of pynput for one project and a later version for another project, you can do this with two separate virtual environments, whereas if you installed pynput on your system, upgrading pynput would break your first project. More info on virtual environments
When you open command line and run pip install, this installs the package onto your system interpreter. You'll instead need to 'activate' your virtual environment and run the pip install there. You can find the path to your virtual environment by opening your interpreter settings in your IDE. Then follow these instructions to activate your virtual environment and run the pip install on your project interpreter.
Try this
pip uninstall pynput
pip install pynput
or
install pynput using conda
conda install pynput