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.
Related
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.
I have an executable python script which archives data from mysql server using the pymysql library. The script works well from the command line.
I call this script from a php script using escapeshellcmd function and I've gotten it to work.
I also have created a bash script that I intend to use from crontab to archive the information as well. I can make this script work as well, by making changes outlined below.
Somehow I have gotten into python versions and path problems.
if I include
#!/home/tim/anaconda3/bin/python
as the first line of the python script it works when called by the php script (using www-data as the user, I believe). It doesn't work from the bash script or the command line, giving the following error:
File "./signal_archive.py", line 22, in <module>
import pymysql
ModuleNotFoundError: No module named 'pymysql'
However, if the first line of the python script is as follows:
#!/usr/bin/python3
the script works from the bash script and the command line but not from the php script. It gives the following error:
File "/home/tim/python/commodities_related/signal_archive.py", line 23, in <module>
import pandas as pd
ModuleNotFoundError: No module named 'pandas'
Both packages are installed on my system. Thinking pointing the script to the path would help, I added the following to the python script but no luck so far.
sys.path.append('/usr/lib/python3/dist-packages:')
sys.path.append('/usr/local/lib/python3.5/dist-packages:')
There is obviously something I'm missing; I think it is that php script is called by www-user and I don't know the default path. The bash file is called by my user with the path specified in the .bashrc file. However, I may need to point the apache or php (www-user) to use a specific installation of python.
EDIT-
To be more clear, a php script (phpfile1.php) calls the python script. When I call phpfile1.php from another php script (phpfile2.php) running on apache2 I everything works using the
#!/home/tim/anaconda3/bin/python
When I call the same file (phpfile1.php) from a different php script (phpfile3.php) from a bash script it fails.
Additionally, if I run the file in place using the following
./signal_archive.py
I get the error but if I run it using the following command it works:
python signal_archive.py
Any ideas if this is right or how to do it? Thanks.
I fixed this in 2 steps:
It turns out that I needed to add the path to anaconda3 to my .bash_profile file.
export PATH="/home/tim/anaconda3/bin:$PATH"
When anaconda3 is installed it modifies the .bashrc file with the previous code snippet. However .bash_profile made the difference in this case.
I also modified the top of the python file to use the anaconda path for execution, as well as add the path for the specific python packages.
#!/home/tim/anaconda3/bin/python
import sys
sys.path.insert(1, '/usr/local/lib/python3.5/dist-packages')
I have a problem with my apache server (Shared Hosting, no root).
I've installed a python package via SSH-Terminal (with pip install) under ./local/lib/python2.7/site-packages/.
There is a python file which imports this package. When I run the python file via the SSH-Terminal everything works fine.
But when I run the python file within a php exec command
exec("/usr/bin/python myscript.py 2>&1", $out, $result);
an error occurs:
"ImportError: No module named XXX".
Do you know what went wrong here or what I can do to make the script work in the browser as well?
Thanks in advance
Is there a simply way to download/save a Python script hosted on Github and then import a function within that script? I could manually save it and then import the function I need (of course), but I'd like to find a more self-contained solution. Ideally, I'd like to be able to send it to someone and have them run my script without having to manually download anything.
Any help?
You could use setuptools and write custom setup script for your package. Wrap your script into python package.
So users will be able install it via pip with just a single line:
pip install git+https://github.com/yournickname/reponame.git
I am trying to import the web module of python to create a simple Hello World program on my browser using web.py.
When I run it from the command line I am getting errors about the web.py package. If I run it from IDLE, it works fine.
Sometimes the problem is in the PYTHONPATH, and the IDE modify the environment variables so when you run it from there you don't have a problem.