I have this error when running the script from terminal but works from PyCharm
C:\Users\Username\PycharmProjects\Space Invaders>python main.py
Traceback (most recent call last):
File "main.py", line 1, in <module>
import pygame
ModuleNotFoundError: No module named 'pygame'
This is how my file directory looks:
https://i.stack.imgur.com/s9qB5.png
I am using python 3.8 and pygame 2.0.1
Should I have to install pygame globally for me to run the script from command line? I have the package installed in a virtual environment.
You're trying to execute the script with global python which doesn't have the pygame package installed. So, you have to activate the virtual environment first. To do this, go to venv/Scripts/ and there will be an "activate" file that you need to execute. Once you have done this you can run your script and it should work.
More info on: https://docs.python.org/3/tutorial/venv.html
Related
I'm not able to run a Python script from ExecuteStreamCommand.
These are the processor properties:
Command arguments: /home/directory/test.py
Command path: /bin/python3
Working directory: /home/directory
Error message: Traceback (most recent call last): File "/home/test.py", line 1, in import nipyapi ModuleNotFoundError: No module named 'nipyapi'
The way that I am able to get ExecuteStreamCommand processor to run python scripts with imported modules is to install the imported modules on the actual machine itself. Therefore, this means running pip or pip3 install {insert module name} on the command prompt for each system that this processor is running on.
I installed python 3.8.8 and installed wxpython using pip at terminal
pip install wxpython
and i run simple program
import wx
print(wx.version())
in pycharm and pycharm`s python console, I got
ModuleNotFoundError: No module named 'wx'
in IDLE, I got
Traceback (most recent call last):
File "C:/Users/tasoo/OneDrive/Desktop/wx.py", line 1, in <module>
import wx
File "C:/Users/tasoo/OneDrive/Desktop\wx.py", line 2, in <module>
print(wx.version())
AttributeError: partially initialized module 'wx' has no attribute 'version' (most likely due to a circular import)
in python.exe code works
I want to import wx in pycharm project.
I tried add python in system path but it didn`t work.
You have problem because you saved code in file wx.py and now import wx loads your file wx.py instead of module wx. Rename your file - ie. main.py instead of wx.py
PyCharm may have own Python installed and it may need to install wx in this Python.
Check
import sys
print(sys.executable)
to get full path to Python used by PyCharm and then use this path
/full/path/to/python -m pip install wx
Or search in PyCharm settings (in menu File) and change Python Interpreter.
In PyCharm for every project you may set different Python - if you have installed many versions.
This is a FRESH installation of Anaconda, so the issues with updating python don't apply here. Uninstalling and reinstalling causes the same errors.
Upon starting up the Anaconda prompt I get this error:
Traceback (most recent call last):
File "D:\AnacondaInstallation\Scripts\conda-script.py", line 11, in <module>
from conda.cli import main
ModuleNotFoundError: No module named 'conda'
C:\Users\xianx>where conda
INFO: Could not find files for the given pattern(s).
I manually added these three lines to my Path variable, but I'm still getting that error upon opening up the Anaconda prompt.
D:\AnacondaInstallation\Scripts,
D:\AnacondaInstallation,
D:\AnacondaInstallation\Library\bin
I also see it when I try to install any sort of package. The system seems to recognize the conda command enough to run conda-script.py.
D:\AnacondaInstallation\Scripts>conda install pytorch
Traceback (most recent call last):
File "D:\AnacondaInstallation\Scripts\conda-script.py", line 11, in <module>
from conda.cli import main
ModuleNotFoundError: No module named 'conda'
D:\AnacondaInstallation\Scripts>where conda
D:\AnacondaInstallation\Scripts\conda.exe
D:\AnacondaInstallation\Library\bin\conda.bat
My problem was that I had multiple Python installations all over the place. Once I cleaned those out of my PATH environment variable and put in the Anaconda ones, the issue resolved itself.
import pyinputplus as pyip
while True:
prompt='Want to know how to keep an idiot busy for hours?\n'
response=pyip.inputYesNo(prompt)
if response=='no':
break
print('Thank you. Have a nice day.')
When I run my above code , I get this error:
Traceback (most recent call last):
File "c:\users\XXXXXX\mu_code\idiot.py", line 1, in <module>
import pyinputplus as pyip
File "c:\users\XXXXXX\mu_code\pyinputplus\__init__.py", line 15, in <module>
import pysimplevalidate as pysv # type: ignore
ModuleNotFoundError: No module named 'pysimplevalidate'
I cannot figure it out. The module is definitely installed. I've even moved it from the folder it was originally installed in to the mu folder where the py file is saved. Any help would be appreciated.
The ModuleError says that you do not have pysimplevalidate installed.
Using the same python executable as you are using to run your script (idiot.py), run
python -m pip install pysimplevalidate
or, even more bullet-proof:
<path_to_python.exe> -m pip install pysimplevalidate
If you are not sure what python executable the script is using, you can check it with
# put this on top of your script
import sys
print(sys.executable) # will print C:\path\to\python.exe
I'm trying to execute a python script with selenium module via batch file.
The python script itself runs perfectly OK, but when I try to execute the script through a .bat file it gives me the error 'ModuleNotFoundError: No module named 'selenium''
from selenium import webdriver
driver = webdriver.Chrome(executable_path='C:/Temp/chromedriver.exe')
driver.get('http://www.example.com')
C:\Python\Python37\python.exe C:\PythonTest\testFile.py
The error printed is:
Traceback (most recent call last):
File "C:\Users\ElGregory\PycharmProjects\PythonTest\testFile.py", line 1, in <module>
from selenium import webdriver
ModuleNotFoundError: No module named 'selenium'
Which obviously is a Python error, but when the code is run in Pycharm it runs as expected. (=selenium installed correctly)
Any help apreciated.
This could be because when you are running inside Pycharm, the libraries are installed in your virtual python environment (venv).
Either activate the virtual environment before running the python file for which you can read more at https://docs.python.org/3/library/venv.html
Or install your libraries globally