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
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 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 a Python script that checks statuses of list of urls defined inside it.
I'm importing and using requests library inside the script. I need to run this script on Jenkins instance which have Python 2.7 installed.
The thing is it doesn't contain requests library installed in Jenkins instance. I don't have access to manually install requests library using pip in the Jenkins instance.
What I need if there is a way is to download the requests library dynamically using shell commands or something and use that wheel file (which is located in some downloaded folder and point to that directory) to act as library for the scrip I'm about to run.
My goal is to run a Python script that uses Anaconda libraries (such as Pandas) on Azure WebJob but can't seem to figure out how to load the libraries.
I start out just by testing a simple Azure blob to blob file copy which works when run locally but hit into an error "ImportError: No module named 'azure'" when ran in WebJob.
example code:
from azure.storage.blob import BlockBlobService
blobAccountName = <name>
blobStorageKey = <key>
containerName = <containername>
blobService = BlockBlobService(account_name=blobAccountName,
account_key=blobStorageKey)
blobService.set_container_acl(containerName)
b = blobService.get_blob_to_bytes(containerName, 'file.csv')
blobService.create_blob_from_bytes(containerName, 'file.csv', b.content)
I can't even get Azure SDK libraries to run. let alone Anaconda's
How do I run a python script that requires external libraries such as Anaconda (and even Azure SDK). How do I "pip install" these stuff for a WebJob?
It seems like you've kown about deployment of Azure WebJobs, I offer the below steps for you to show how to load external libraries in python scripts.
Step 1 :
Use the virtualenv component to create an independent python runtime environment in your system.Please install it first with command pip install virtualenv if you don't have it.
If you installed it successfully ,you could see it in your python/Scripts file.
Step2 : Run the commad to create independent python runtime environment.
Step 3: Then go into the created directory's Scripts folder and activate it (this step is important , don't miss it)
Please don't close this command window and use pip install <your libraryname> to download external libraries in this command window.
Step 4:Keep the Sample.py uniformly compressed into a folder with the libs packages in the Libs/site-packages folder that you rely on.
Step 5:
Create webjob in Web app service and upload the zip file,then you could execute your Web Job and check the log
You could also refer to the SO thread :Options for running Python scripts in Azure
In addition, if you want to use the modules in Anaconda, please download them separately. There is no need to download the entire library.
Hope it helps you.
You can point your Azure WebJob to your main WebApp environment (and thus its real site packages). This allows you to use the newest fastest version of Python supported by the WebApp (right now mine is 364x64), much better than 3.4 or 2.7 in x86. Another huge benefit is then you don't have to maintain an additional set of packages that are statically held in a file somewhere (this gave me a lot of trouble with dynamic libraries with crazy dependencies such as psycopg2 and pandas).
HOW: In your WebJobs files, set up a .cmd file that runs your run.py, and in that .cmd file, you can just have one line of code like this:
D:\home\python364x64\python.exe run.py
That's it!
Azure WebJobs looks at .cmd files first, then run.py and others.
See this link for an official MS post on this method:
https://blogs.msdn.microsoft.com/azureossds/2016/12/09/running-python-webjob-on-azure-app-services-using-non-default-python-version/
I am writing a project which uses data from a database. Now I wanted to package it and have made a setup.py for it using help from here. Now when I run setup.py from terminal it installs the package. The database is created using a create_db.py script and it is created in the created in the same directory as the script. So obviously it doesn't work after I install the package since its not accessible from there.
I am looking for a way to create the database from the script at the time the package is being installed. Is it possible?
Add this to your main script?
import time
time.sleep(5)
execfile("./create_db.py")