py-spy: how to run scripts with dependencies? - python

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.

Related

How do I add my own Python scripts to a pipenv?

I created a pipenv when trying to publish my code, which has several python scripts. Unfortunately, the pipenv only seems to use index.py (my code is a REST API for AWS Amplify) and when I use import [scriptname] I get an error saying that the module doesn't exist. Specifically, 'ModuleNotFoundError' even though it's in the exact same directory as all the other py scripts. When running it locally, before creating the pipenv, all the code worked fine and the scripts were able to import and call each other without issue.
I'm sure I'm doing something wrong that's very basic/simple because there is virtually zero information about how to do this.

Python script not running in SSIS package

I have python script running from SSIS package.
I am running python script in ".bat" file.
If I Execute SSIS package, it is running fine. Same package if I deploy and run/scheduled run it is failing with below error:
error: In Executing "D:/SSIS/PYTHON_SCRIPT/task.bat "D:/SSIS/PYTHON_SCRIPT/". The process exit code was "1" while the expected was "0"
Any one have similar issue. Help me to solve this.
Make sure your Python Libraries are correctly configured and check Environment Variables as well

PyCharm Run Doesn't Recognize Packages But Console and Terminal Are OK

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.

Suddenly .py files can't import modules but still works with CMD

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.

Path import error

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.

Categories

Resources