I am new to python and trying to run code from existing project. I am getting the below error:
Traceback (most recent call last):
File "/xxxx/xxxx/Library/Application Support/JetBrains/IdeaIC2021.1/plugins/python-ce/helpers/pycharm/_jb_pytest_runner.py", line 2, in <module>
import pytest
ModuleNotFoundError: No module named 'pytest'
The file is present in the mentioned path.
I see that there are many questions regarding this but nothing seems to provide me with a solution.
I am using the IntelliJ IDEA IDE.
The error message is telling you that File "/xxxx/xxxx/Library/Application Support/JetBrains/IdeaIC2021.1/plugins/python-ce/helpers/pycharm/_jb_pytest_runner.py" is trying to import pytest but fails to find the package. That is, it's not the presence of that file that's failing, but that it can't find pytest in order to import it.
Install pytest using
python3 -m pip install pytest
Change python3 accordingly to use the specific installation of python that you're using in the IDE.
This is because you don't have the needed environment.
Since you use the Pycharm, you can try to install pytest.
https://blog.finxter.com/how-to-install-a-library-on-pycharm/
This worked for me. Repeating here:
Open IntelliJ's settings/preferences
Go to Tools -> Python Integrated Tools
Under Testing...Default test runner: choose pytest
Click the Fix button that appears in the bottom of the panel
Related
All of my project files in VS code suddenly gives an error saying that it cannot import modules (even tho the modules are local i.e same directory and they used to work pretty well before).
The code works fine in pycharm but not in VS code, any idea whats going on?
Code:
from backend.util.crypto_hash import crypto_hash
from backend.config import MINE_RATE
error:
env DEBUGPY_LAUNCHER_PORT=34625 /home/nikhil/python-blockchain/blockchain-env/bin/python /home/nikhil/.vscode/extensions/ms-python.python-2020.3.71659/pythonFiles/lib/python/debugpy/no_wheels/debugpy/launcher /home/nikhil/python-blockchain/backend/app/__init__.py
Traceback (most recent call last):
File "/home/nikhil/python-blockchain/backend/app/__init__.py", line 2, in <module>
from backend.blockchain.blockchain import Blockchain
ModuleNotFoundError: No module named 'backend'
Close VS Code,
start it again, Go to File > open folder (open your project folder in vs code),
if it gives a prompt to select a existing virtual environment, select that.
Then you should be good to go.
More unrelated information:
I assume the issue here is that there's some problem with VS Code not recognizing the virtual environment properly. This has happened to me several times and I cannot point out why that happens. But the above solution is a quick fix and always works for me.
I'm not sure if this will resolve OP's (ten-month old) question, but I've been struggling with the same error using debugpy while trying to configure VSCode's debugger.
Step 4 of this resource resolved the issue for me. In particular, I was using the -m flag when running debugpy, but the module to be run was not in the current working directory. Once I had changed this, the debugger worked as expected. As an example, if the command was originally:
python -m debugpy --listen 0.0.0.0:5678 ./some/directory/my_script.py
then the following two commands would rectify it:
cd ./some/directory
python -m debugpy --listen 0.0.0.0:5678 ./my_script.py
After doing this, I no longer received the "No module found" error.
The main reason is that VSCode does not automatically configure environment variables for you, but PyCharm does. The simplest method is adding your module file to system path.
import sys
sys.path.append(module_file_path)
The better solution is to config your environmental path named PYTHONPATH, adding related module path to it, and after that you will no longer need import system path manually.
Hope it works!
I created a project in Pycharm including a gp.py, copied the project folder to another machine and tried to run the gp.py script from command line using python gp.py. However I got a error
Traceback (most recent call last):
File "gp.py", line 2, in <module>
from gplearn.genetic import SymbolicRegressor
ModuleNotFoundError: No module named 'gplearn'
The thing is I could see this gplearn library I used in the project folder, like below. The screen shot is not from Pycharm but the folder I copied to another computer. I tried to place the gp.pyinside and outside venv folder but neither worked. Could you please help to point out what the problem is ? Many thanks
gplearn package is not installed in the new machine.
Go to cmd prompt/terminal in pycharm and execute below line:
pip install gplearn
Sound like you are seeking for a method to deploy your script to end user, in this case maybe you can give Pyinstaller a try.
I'm not too familiar with mac, but I fired up pycharm to run a script I made that uses the zenpy module. Problem is when I try to execute it, I get the error
Error Message:
Traceback (most recent call last):
File "/Users/thisisfake/PycharmProjects/untitled1/venv/bin/test.py", line 29, in <module>
from zenpy import Zenpy
ModuleNotFoundError: No module named 'zenpy'
The obvious answer is, oh, I forgot to add the module to zenpy. So I went to File -> Preferences for New Projects -> Project Interpreter and added zenpy. Tried the script again, no dice. Check the project interpreter and zenpy is definitely there. I tried creating a new project entirely and re-adding it that way and no success. Tried moving the script to the bin folder, no luck. Added zenpy via pip in terminal, same result. I'm definitely missing something obvious, any idea what it is?
Thanks!
Select View -> Tool Windows -> Terminal
pip install zenpy
I am trying to import the thing in python that will enable me to copy and past things. It seems to have a problem. I later searched my entire C drive for pyperclip and it seems to be not have it at all. How can I go about fixing this? Or am I not looking in the right area? Here is the error:
import pyperclip
Traceback (most recent call last):
File "", line 1, in
import pyperclip
ModuleNotFoundError: No module named 'pyperclip'
BTW I'm on windows 10
You seems a new learner for Python. You can try to install that package via pip command. For other problem like how to use pip or which user to run pip, just go to search and solve it by yourself.
So yes you're right. You need to open up cmd prompt. use the cd to change the directory to the one inside Python36\Scripts. Then run the command
pip install pyperclip
I'm trying to use Pybuilder to build and then run my python project unittests. Everything goes well in the build process, but when it goes to run my unittests I receive the following error message:
File "/Users/username/Desktop/Work/pythonutilities/tests/test_elastic_controller.py", line 5, in <module>
from src.elastic_controller import ElasticController
ModuleNotFoundError: No module named 'src'
It can't seem to import the src module.
However, if I then create a task that executes a separate setup.py install (via command line using the subprocess library), it works perfectly. Pybuilder should be creating and installing it's own setup.py though, correct? So this shouldn't be a problem or a suitable solution.
I'm not sure where to go next, any help would be appreciated.