I'm running python 2.7 on windows. Both python27 and python27/scripts are added to the PATH, which I've verified on the command line. I used easy_install to download SOAPpy, and I have a simple python program that calls import SOAPpy at the top.
On the command line, running
python sample.py
works, as does importing in the interpreter. However running simply
sample.py
Tells me:
ImportError: No module named SOAPpy
I'm sure this is some sort of path error, but I don't understand what's going wrong. What's the difference between these two calls and how do I fix the issue? I'm sure this is a really newbie question but I'm not sure what to google. The fact that it works in the interpreter is making me scratch my head.
Related
Running PyCharm 2020.1.2 Community Edition in Win10 with a Python 3.6 venv as interpreter. Installed the package feature-engine through the Project Interpret interface, installs fine and appears in the list. I can successfully import feature_engine in the PyCharm console, and I can use it fine. I can also execute a .py file with this import statement in the Terminal with the venv activated, and it also works fine. However, when I try to Run the same .py file with the import statement, I get:
ModuleNotFoundError: No module named 'feature_engine'
I have tried using import and importlib, thinking the issue was the hyphen, but those didn't work. I have tried uninstalling and reinstalling, restarting PyCharm, etc. Nothing seems to work. Any suggestions how to get the Run function working?
EDIT: Thanks for the suggestions. Attached are the Run configuration and the Project interpreter configuration. As far as I can tell, the environment is the same.
Below are examples of the error trace. The object being Run is a Flask app, which imports packages that use the feature-engine library. The actual import statement in the final import is simply import feature_engine. Trying to import the method directly using from feature_engine import variable_transformers as vt also fails.
Make sure you're using the right configuration to build your program (that is, using the python executable of the right enviroment). You can check this in the top right corner, where the run button is.
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!
running the following on windows 10
C:\code\EPMD\Kodex-1.4.6\EPD_Prerequisite\Anaconda2\Scripts/py-spy.exe --nonblocking -- python C:\code\EPMD\Kodex-1.4.6\Applications\EPMD-Software\Preprocessor/Main.py
gives
import error, no module named <>
even though the script Main.py is running fine.
How do I make py-spy recognize imports?
This should just work. Can you create an issue on github?
As a work around, you can run the program yourself and get py-spy to profile it by passing the PID.
I have a weird issue.
Main issue:
My .py files that used to work fine like 3 hours ago now can't import any external modules. I can still run them from Spyder (similar to a PyCharm editor) and from CMD with python run.py. However when clicked on I get the error ModuleNotFoundError: No module named ModuleName. However the module is found when running through everything else, the module is there in the Anaconda libs; the folder doesn't have any permisson restrictions, and it's not just one file it's any .py file that imports an external module.
At first I thought this may be a pip issue as I had just update to pip 18, but even when retracting to pip 10.0.1 the issue remains.
[EDIT]: I've tried making a PyInstaller .exe and that still works as intended, however the app still doesn't work with cx_freeze even though it used to a fez hours ago.
Backstory:
I was playing around with PyInstaller and Cx_Freeze to turn my app into an executable.
I have my working .py file that I edit and test inside of the Anaconda's Spyder app.
And so I'm testing the executables, and they work fine, just like my python code. The Pyinstaller standalone and the cx_freeze app work as intended.
So I change a few things in the main .py file (nothing crazy just removed a print('')), reuse cx_freeze and then at some point I start working on a setup wizard for my cx_freezed app.
It's all good except that when running the app, the cmd prompt just closes.
I think 'huh weird', I test the .py file in Spyder it works fine, so I screenshot what's written on the cmd : ModuleNotFoundError: No module named ModuleName, so I think it's an issue with the Wizard installer, so I try the original .exe file, same error. So I try the .py file and to my desmise, same error. I double check the modules, reinstall them succesfully, error persists.
And so I try to run a backup I know for sure worked and in which I haven't edited anything, and now same error.
This is really anoying as I want to make a .exe of the app, managed to and now nothing works anymore
Here are some things you can try.
Add this code to get a print out of the system path.
import sys
from pprint import pprint
pprint(sys.path)
That should tell you all the paths where modules can be loaded from. If your file is not in one of the paths it won't be loaded.
For a bit more info you can run python with the -v flag and it will verbosely let you know what is going on as python starts as well as when you attempt to load modules. You may be able to glean information about what is going wrong that way.
I think you used the wrong version when you converted from a .py to .exe. Generally the CMD uses whatever's in the ENV vars, so just make sure all version numbers are the same.
I have a script which works fine on the terminal. I'm trying to tie it to a jenkins job, which essentially only needs to run the python script. So I've written a little shell command at the bottom which calls the script.
However, when it runs, it throws the following error:
ImportError: No module named request
It's coming from this line:
import urllib.request
I've tried changing the shebang from python2.7 to python3, but then I get the same error but for the pkg_resources module, which sits right below the first one.
import urllib.request
from pkg_resources import parse_version
Seems like it should be an easy fix but it's not so far. Does anyone know what I need to do to get Jenkins to recognize these python modules? Again, no problems importing either of these modules on my Terminal.