How to run python production on customer environment - python

I have some python application that should run on customer site. I compile my py files to pyc (python byte code).
What is the standard way to run the app on the customer environment? The options I see are:
As part of my installer, install some python distribution, i.e Anaconda.
Require the customer to have python installed in their environment.
Bring python libraries and executable along with my code and run it directly from my installation dir.
Convert the scripts to exe using some py-to-exe tool.
Application usage: The app is used as a tool to calculate statistics for my main product. The customer won't run it explicitly. It won't have any GUI.
Customer environment will be x64 Windows machine. No other restrictions.
Any recommendations or comments? I couldn't find such discussions on the web.

Given your requirements, the last two options seem most viable:
Bring python libraries and executable along with my code and run it directly from my installation dir.
Convert the scripts to exe using some py-to-exe tool.
You can either package your code, or freeze your code and create an executable for the target OS.
Given your requirements, I'd suggest the latter. You can go through the Python Packaging Guide for more details regarding packaging.

Related

Convert python script to an executable file or icon for Windows?

What is the simplest tool to convert a python script into an executable file?
I made a python script and requirements.txt which contains necessary packages for a virtual environment with python3.6. I gave them to my client so that he can create a virtual environment and execute the file by executing the three lines below in the console.
source activate
python __main__.py
deactivate
Basically he needs to run it once a day, so that my python script scrapes a stock index data release at the end of each day and does some data transformation and saves the data in a desired directory as excel files.
However my client told me "even the three lines are difficult for people who are not familiar with CUI. Can you make it like a clickable icon?"
Is there any tool that can easily package my python script and required packages as an executable file or icon? It doesn't have to be cool. A simple and primitive tool would serve our needs. My client has Windows 10 Pro 64bit but it has to be something that I can develop in my My work environment which is Mac OS Catalina.
Thank you!
Yes, it is possible following library's help with this.
PyInstaller can be used, under Mac OS X, Windows, Linux,...
For an example i would read this medium post, it should contain everything to get you started.
py2exe can be used if you only want an executable for the Windows platform.

Unable to run python in CMD

I have recently started learning python using code academy and today I downloaded everything that I thought I would use. I downloaded Python and Atom. I have two separate drives on my computer. An SSD with not much storage and a hard drive with a lot of storage. My Windows is installed on the SSD, but I wanted to download python and atom on the hard drive, so I did so. When I installed Python I made sure to check add to PATH and the environmental variable thing. Now when I go to the command prompt, it shows "C:\Users\Gustavo>" but my python is installed on a different drive. Is there a way I could make this work? Thanks a lot.
There are two ways to install python:
Download directly from the website
Use a package manager
Case 1: Download directly from the website
Go to the python's website to download the version you would like to use.
Install the downloaded file (During the installation you can customize the installation directory)
Make sure to enable "Add python.exe to Path"
After installation has been completed, open your command prompt and type where python. Your python directory should be printed.
If all is good, then typing python should launch python in your command prompt. You can also run python by cd in the directory where your python is located and launch the .exe
You have mentioned about changing path and environmental variables, and that's probably for the purpose of keeping multiple versions of python. If that's the case, there's actually a quick fix for this:
Go to the folder where you installed Python.
Copy the python.exe file, and rename that copy in the same directory as python3.exe (If you installed version 2, then rename as python2.exe).
Now in command prompt type python2 or python3 and you should be able to launch either versions respectively.
Note: If you face issues regarding paths, then you should detail the error messages.
Case 2: Use a package manager
Choose a package manger: chocolatey, scoop, and others.
Check out these links for changing package manager's installation directory, installation method varies by the managers, so you should consult the developers should you experience problems:
chocolatey
scoop
Package managers will manage the versions for you, if you choose to install multiple versions. You should refer to the package manager's website for detailed information. However, you can quickly check the installed version by typing python --version. The python version number should be printed back to you, same applies to python3.
Double check your installation directory by which python
Type python or python3 to run your python of choice.
Lastly, you have mentioned atom. Atom is just a text editor: you can write python codes with it.
When you are done editing, you can open the command prompt and navigate to where your code resides, and type
python filename.py
This will run your code directly from the command prompt. There are many atom plugins available to make this process seamlessly integrated within atom. iPython and Jupyter plugins are first things that comes to my mind, you should specifically check out Hydrogen.

How to make python portable?

I want to make a portable app that would have some code and python executable that would run on any Windows even if python is not installed.
I would like it to be python 3.6 and so it has only pip and setup tools installed.
EDIT: concerning duplicate
not quite. I don't want to compile the code. I wanted to give them .py files but realize that Windows won't have python installed on default. I want something that can be carry on a flash drive but will run my code from source not binary.
Please correct me, if I understood it wrong. I think there are at least two ways to do it.
suppose you have one portable_run.py script you want to run everywhere on a flashdisk.
Make a exe file with pyinstaller for example. you can get a exe file like portable_run.exe. On target windows system what you need to do is to run the exe direcltly protable_run.exe
Use a portable python distribution like winpython or python-xy. you just need to copy this portable distribution on the flash disk together with your portable_run.py. To run it on target system flashdisk/path-of-winpython/python portable_run.py
Hopefully it could give you some idea.
I also encountered the same problem and managed to create a portable python with Python's official Windows embeddable package.
I wrote the steps into a ps1 script so I can easily repeat the process without going through the pain.
The steps:
Download the portablepy.ps1 from the repo :
https://github.com/Dreamsavior/portable-python-maker
Create a blank folder, put the portablepy.ps1 to that folder.
Execute the portablepy.ps1
The script will create a portable python 3.9.10 with pip in the current folder by default.
To install custom version of Python run the script with -source and -destination parameter
.\portablepy.ps1 -source "https://www.python.org/ftp/python/3.9.10/python-3.9.10-embed-amd64.zip" -destination "C:\SomeDir\PortablePython\"
Where the -source is the url of the Python's Windows embeddable package from this page: https://www.python.org/downloads/windows/
And -destination is the path of your folder (ended with backslash).

How to integrate different installation packages into single execution file in Python

I have project which contains about 20 packages which are required to be installed in Python, to support all commands in code. And I want whole project to be single file which contains inside all relevant installations and program code itself. So to need only run this file, and all desired behaviour happens automatically. I need to create a build for Windows, and for MacOS.
What are available tools for creating a build of same program into single file - one (.exe) file for Windows, and one (.dmg) file for MacOS, for Python application both?
Is there an implementation option to unify into single installation file - for both Windows and MacOS operating systems? If yes - please explain how.
I use PyCharm as development environment. Is there an option to make a build from PyCharm? Do I need a PyCharm to be installed at all to be able to create installation wizard?

PTVS + Django: why can i not import python libraries

i am following the tutorial found here: http://www.windowsazure.com/en-us/documentation/articles/cloud-services-web-sites-python-django-app-with-ptvs/
I already had django installed on my system. After following the instructions in this tutorial, i noticed that it seemed to have installed django again, but this time under my project's folder (myproject/env/Lib/site-packages).
Why is this?
The other issue i am having is that if i try to import certain libraries using the visual studio editor, it's unable to find the import. However, if do this in the Interactive window, it does recognize the imports. Also, if create a stand-along python (not django) project, i am able to import the libraries fine.
Any thoughts on why this is happening and how to resolve?
The tutorial uses Python virtual environments (virtualenv), which you need in order to deploy your website to Azure. A virtual environment, basically, is an isolated Python environment with its own set of libraries (site-packages etc) that is distinct from your main interpreter. It allows you to have specific versions of packages that you need just for that particular website, and different from the same for some other website of yours.
If you don't plan to deploy it to Azure, you don't need a virtual env - you can skip the step creating it, and instead install Django and other packages directly into your main interpreter. If you do plan to deploy to Azure, you need the virtual env, because the main interpreter installed on the Azure VM will not have any modules other than those in the standard library.
The reason why Python Interactive window lets you import the packages is that the instance you're working with is for your main interpreter. Every registered interpreter, and every virtual env in an opened project, has its own separate Python Interactive window. You can open the window for your virtual env from the Python Environments window, which is available via Tools -> Python Tools -> Python Environments.

Categories