ModuleNotFoundError: No module named 'selenium'
What I tried: Added path to sysdm.cpl Ran multiple commands in terminal in VScode, like creating a venv and path changing.
Note:
Selenium is installed and can be found if I run pip --install selenium, yet it still throws an error when I run script in VScode
I have no clue how to run modules and want to start coding.
This is most likely because multiple versions of python exist on your machine, and the environment where you successfully installed the selenium package is not the same python version as the environment you are using.
Solution:
Ctrl+Shift+P open command palette
search select Python:Select Interpreter
Choose the correct interpreter
What is the correct interpreter?
Select the python environment where the selenium package has been successfully installed
Select the python version you want to use, then create a new terminal to activate the environment, and finally install the selenium package for this environment in the new terminal
You have probably not installed selenium for the same python interpreter that is running your script. In your script, put these two lines at the very top:
import sys
print(sys.executable)
Then run this script like you normally would. This should print the path to the interpreter that is running your script, I'll assume it is /path/to/python
Now try running
/path/to/python -m pip install selenium
in your terminal. This should install selenium specifically for the python version that sits at /path/to/python
Related
I cannot run my python script with imported modules/packages using the VSCode extension for Python, that allows you to run scripts directly from VSCode (the official one from Microsoft). I installed a bunch of packages using pip3 install numpy and the other modules, which I discovered I had to because only "pip" on Mac installs on python 2. Code example below
print('testing')
import numpy as np
import pandas as pd
from openpyxl import Workbook
wb = Workbook()
print('omg this wont work')
When I try to run it using the Run button from VSCode python extension (Microsoft one), it shows up Error as if I didn't had previous installed the modules using pip3.
But when I try to run it on terminal using python3 teste.py it works and imports my modules right.
OS Version: macOS Catalina 10.15.7
python3 --version
Python 3.10.2
python --version
Python 2.7.16
You should choose which python to using in VSCode. Check this documentation to see how it is done: vscode python environments
For default python environment installed in machine:
Press ctrl + shift + p (this will open console at top center)
For mac press command + shift + p instead
In the console type Python: Select interpreter (then hit enter)
You can see list of python interpreters as drop-down options or a single interpreter which is installed in your machine.
Select that and then run your code
Before running your py script make sure that you have re launch the editors terminal.
For custom python environment installed in machine
1.Download anaconda and install it on Mac.
Now in step 3 mentioned above, in the drop down you can find conda environment as well select that and relaunch the terminal.
Once conda environment selected in terminal you can see the (conda) will start coming in your terminal in starting of line.
Also if you are using anaconda environment, do install everything as conda install package_name instead of pip install...
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.
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 opened a Terminal window under MacOS High Sierra and when I run the python command "import cx_Oracle" everything is fine.
When I run a .py file on a PyCharm project, which the very first line of code is "import cx_Oracle" I get the following error message:
"ModuleNotFoundError: No module named 'cx_Oracle'".
I have aliased my python3 command to python and when I run the command "python -m pip install cx_Oracle" I get a message telling me it's alright:
"Requirement already up-to-date: cx_Oracle in /usr/local/lib/python3.8/site-packages (8.0.0)"
I simply don't know what to do. Is that a matter of adding any path to any environment variable or a virtual environment under PyCharm related problem?
Why does my Python Interpreter running through Terminal not alert me about any error, when I run the install command, everything is fine, but through my Python IDE I keep being alerted about a non existent module?
Any help would be much appreciated.
Thank you in advance!
Try installing cx_Oracle using the python binary that PyCharm runs. I.e. with something like:
/Users/cjones/j/PycharmProjects/p1/venv/bin/python -m pip install cx_Oracle
The python binary is shown in the PyCharm Run console when you execute a script.
Hi so I downloaded the source code for beautifulsoup4. I moved it to a folder .../Desktop/Python_modules/ which is where I like to keep all the folders for the modules I down load and tried to install it as follows:
went to the directory
ran:
python setup.py install
How comes now when I open python in terminal i can import beautifulsoup4 using "from bs4 import BeautifulSoup" but when i have it in a script which is executed using ./script it gives the following error: 'ImportError: No module named requests'?
And How would I go about installing beautifulsoup4 so that i can run the script using "./"?
Just for completion: I'm using a mac
The behavior you are seeing suggests strongly that there are two different versions of Python installed on your system. If your scripts start with:
#!/usr/bin/python
Then running ./script will always run /usr/bin/python. If you have another Python installed (say, via homebrew, which will give you /usr/local/bin/python) then running python in the terminal will probably get you that version.
So...running python setup.py install will install the module where it is visible to /usr/local/bin/python but not to /usr/bin/python, which is why it works for you when you run python in the terminal but not when you run a script.
You can fix this by running your scripts like this:
python script
Or by modifying the scripts to start with:
#!/usr/bin/env python
Which will look for a python binary in your $PATH rather than using a fixed path.
(Or you can install modules by running /usr/bin/python setup.py install)