I have a python script that uses the pytz module and it runs successfully on one server. But I have moved the script to a different server (over SSH), and now when I try to run the code there I get:
ImportError: No module named pytz
Is there an easy way I can get it to run? I believe I don't have the permissions to download new modules...
try to install this module on your new ssh server, by using:
python -m pip install pytz
if you haven't permissions to download any module, try to use a common similar, or compile this script to a .sh or .exe runnable file, on your developer machine.
Related
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'm trying to connect the Bybit websocket to Python via this code.
from BybitWebsocket import BybitWebsocket
ws = BybitWebsocket(wsURL="wss://stream-testnet.bybit.com/realtime",
api_key=None, api_secret=None)
ws.subscribe_instrument_info(symbol="BTCUSD")
while True:
data = ws.get_data("instrument_info.100ms.BTCUSD")
if data:
print(data)
I'm new to Python and websockets so I have no idea why this does not work. I have already pip installed the websocket with the command:
pip install bybit-ws. I get the error: "ModuleNotFoundError: No module named 'BybitWebsocket'". It has probably to do something with a path, but I still can't fix it. Any help?
install bybit-ws is the correct command to install the module you are looking to import, but to make sure that your module is being installed within the correct Python environment, perform:
pip3 install bybit-ws
And then run your code. You might otherwise be well installing it into the system Python (likely Python2, if you are on OSX).
You can check that the module is importable in Python3 if you open a Terminal window and type in:
python3
from BybitWebsocket import BybitWebsocket
If the above succeeds, your import will work if you run it from the Terminal with:
python3 path/to/your/script.py
But if you still get the ModuleNotFound error when you run it from your IDE, then your IDE is configured to execute code within the wrong environment.
I have a Python script which has been created to pull data out of a database and present it in an excel spreadsheet. Because multiple people need this script, I have placed the script on a network drive. To run the script, I have also created a virtual environment in a folder on my workstation, which I then copied to the network location. I have a batch file which runs the script using the virtual environment version of Python.
When I run the batch file on my workstation (from the network drive), everything works fine. When another user, who does not have Python installed on their workstation, runs the batch file, they receive the following error:
ModuleNotFoundError: No module named 'contextlib'
The traceback for the error comes from:
virtualenv\lib\site.py
virtualenv\lib\importlib\util.py
Is there something that I am missing when creating the virtual environment? To create it, I used the following commands (on Windows):
mkdir virtualenv
virtualenv virtualenv
\virtualenv\Scripts\activate
pip install [packages required for script]]
\virtualenv\Scripts\deactivate
Any help is very much appreciated.
Thanks for your help. It turns out that a virtualenv does not do what I thought it did. A virtialenv is not portable to other machines/evironments.
I ended up going with pyinstaller to package the script into an application. This was very easy and quick.
To install pyinstaller and create the app, I simply followed the instructions here:
https://www.pyinstaller.org/
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
Here is my problem :
I wrote a python script which works,but only on my machine (when I run it in my interpreter).
I also wrote .bat and .ini file (as I already did for other scripts which work), and when I run the .bat, it says :
import xlsxwriter
ImportError: No module named xlsxwriter
(The other batches I wrote for ohter scripts works well)
xlsxwriter is a new package I installed for this script (I installed in my interpreter (pyCharms))...
so why my batch doesn't work while my script does ? Do I have to dwnld/install the package/module somewhere else ? Where ?
When the problem is fixed, I'd like to share my .py ,.bat, .ini files with my colleagues so they can run the batch as well. What will be the steps ? Will they have to install/dwld the package as well ?
Yes, xlsxwriter must be present on any machine on which you want to run your script. The easiest way to install it on the host is with pip:
$ pip install xlsxwriter
You can also include a requirements.txt file with your script that includes xlsxwriter in it, and users can run the following:
$ pip install -r requirements.txt
More on pip and distributing packages that have 3rd party dependencies: https://pip.pypa.io/en/stable/