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.
Related
I'm learning how to execute python files and functions through node. I've been following this tutorial https://medium.com/swlh/run-python-script-from-node-js-and-send-data-to-browser-15677fcf199f which shows a very simple setup.
I had no problem doing this. Now, when executing a python file i have in a python project i created using Pycharm, i get a stderr like this 'ModuleNotFoundError: No module named 'requests''.
Inside the project i import a lot of modules and have a venv folder that Pycharm created as i wanted to use a venv to avoid problems with my dependencies. Please correct me, but i understand this error is caused because when node executes the file, it is not using the venv of my Pycharm project, so fails because it obviously never installed those packages.
So my question is, how can y execute the file from node, but in the context of the venv, so whenever it sees an import statemnt in python it knows the package, since it's inside the venv, does that make sense?
My current spawn statement looks like this: const python = spawn("python", ["main.py"], {cwd: "path/to/file/dir"});
I've read lots of questions in the forum, but none helped me to solve this, help is much appreciated!
*Attached is a picture showing how this venv folder Pycharm creates looks like.
I have two files - one PHP file and one Python file. The python file imports the Jira module, searches for issues, and obtains information from Jira. This file does function correctly and it will find Jira issues and return all needed fields successfully.
The PHP file (for this example, let's call it py_exec.php) is part of a website and executes the Python file through shell_exec; something to the effect of:
$jira_issues = shell_exec(python3 py_search.py issue=blah);
print_r($jira_issues);
When I run the Python script directly, the script works correctly.
When I execute the PHP script directly, which in turn executes the Python script, the script works correctly.
But when I run the PHP script from the website, the script returns nothing.
After troubleshooting a bit, I tried to run the command as the apache user and I am given the following error:
ModuleNotFoundError: No module named 'jira'
Obviously the module is installed, but it seems that it's not accessible to Apache.
How do I make this module accessible to Apache?
Many thanks, in advance, for any help I can get.
su to the apache user and run pip install jira. Check that it worked by doing python and then import jira.
Sometimes pip ends up aliased to something other than python. So if you have issues, try python -m pip instead.
I have project where I have created multiple python files based on its usage. It works completely fine when I run from the pycharm. However, when I run the same from the terminal, I get the error: ModuleNotFoundError: No module named 'dataflow'
I need to make the dataflow out of this and need to deploy and it is giving an error while doing so.
Folder structure of the project, this works when I run from PyCharm
Error while running it from the terminal
Adducated guess, runs pychar your code in venv too? If not you might check if you installed the package that is missing in your venv.
Update
if you intent to have a dataflow package that you want to import and use the modules in it you need a __init__.py file in your dataflow folder. this makes it a package for python. If you want to use the modules in dataflow with the . in an import you need to do an import in __init__.py
like so
import .driver_main
this makes stuff from driver_main available in dataflow but better practice would be to specifiy what you want to access from driver_main like
from .driver_main import MyDriver
this will gibe you access to my driver via
dataflow.MyDriver
If you really just want to acces stuff from one module on the same lvl you should able to do so with the same approach. so in you exaple you showed in the picture try to change
from dataflow import driver_main
to
from . import driver_main
this would apply to an import in a module on the same lvl as driver_main.py like app.py
Update on Comments in original post
btw the env in pychar has nothing to do with the venv in the console. You simply telling pycharm to use python 3.7 but with your venv you copy binaries in a folder stucture. that said if you run an virtual environment all stuff you pip there gets copied in this folder structure not in the global site-packages. This means if you installed stuff global you wont have it right away in the virtual env and the other way around!
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 get the error in question when I attempt to create a project. I followed the instructions found at how to install python an django in windows vista.
Also make sure that you have permission to access all of django's files. I've seen these kinds of errors happen because of permissions issues before.
EDIT: I haven't tried it out, but there's a link on that page to Instant Django, which looks like a pretty easy to set up.
You can get around this problem by providing the full path to your django-admin.py file
python c:\python25\scripts\django-admin.py startproject mysite
Most likely you don't have Django on your Python path. To test, quickly fire up Python and run:
>>> import django
If that fails, it's just a matter of getting Django onto your Python path. Either you set the environment variable, or you move django into your python2x/Lib/site-packages directory. If it does work, try importing core. If that fails there, then something is probably wrong with your Django install.
From your command line (cmd) run "ftype Python.File" and make sure that your .py files are being executed by the correct version/installation of Python.
It's possible another application has surreptitiously changed this under the hood.