This question already has answers here:
How to determine which Python install is being used by the interpreter? [duplicate]
(1 answer)
How do I check which version of Python is running my script?
(26 answers)
Closed 8 years ago.
I have a series of unit tests that are meant to run in two contexts:
1) On a buildbot server
2) in developer's home environments
In both our development procedure and in the buildbot server we use virtualenv. The tests run fine in the developer environments, but with buildbot the tests are being run from the python executable in the virtualenv without activating the virtualenv.
This works out for most tests, but there are a few that shell out to run scripts, and I want them to run the scripts with the virtualenv's python executable. Is there a way to pull the path to the current python executable inside the tests themselves to build the shell commands that way?
The current python executable is always available as sys.executable, which should give full path (but you can ensure this using os.path functions).
Related
This question already has answers here:
How can I distribute python programs?
(8 answers)
Closed 2 years ago.
I have developed some scripts which I need to share with colleagues who does not have python nor have underlying distributions to run it. How to automatically configure environment and more importantly run the script without even python installed?
I saw some solutions on SO like py2exe. Not sure that it’s the best option. Docker is also not possible since in my case I need something what can work simply by running python3 path/to/program
You can use online coding platforms like repl.it to run scripts from the browser so u don't want to install python locally.
Convert it into a exe file using pyinstaller
Following are the steps:
1. Open cmd on the folder in which you stored your py file
2.type it on the cmd
pyinstaller -- onefile filename.py
If you don't have pyinstaller module then install it using
pip install pyinstaller
It depends on the complexity of the script.
If it is doing complex things that it needs to be run on your computer for, like file input & output, then PyInstaller is probably the way:
pip isntall
pyinstaller -- onefile script.py
If it is just a short script, then Repl.It is a great way to save and share scripts that can be viewed and run right in the browser. It supports installing pip packages and environments. It even has a feature where you can host a terminal app as a website: repl.run
I am using PyInstaller to create a complete standalone executables, that does not depend on a machine having python interpreter. Here is a complete guide: https://datatofish.com/executable-pyinstaller/
This question already has answers here:
Sublime text3 and virtualenvs
(5 answers)
Closed 2 years ago.
In other words, how can i build a system using python from virtual environment where i got all my packages installed.
Ty in advance!
I haven't used it myself, but it looks like the Virtualenv package in Package Control does exactly what you're looking for. Please read through the README thoroughly, as it explains how the package works and which settings need to be set manually so that it will work.
Essentially, what it's doing under the hood is finding the Python executable in your virtualenv and creating a custom build system with the path to that executable, so the proper modules will be accessible during the build. It claims to work with both venv and virtualenv environments.
This question already has answers here:
Can existing virtualenv be upgraded gracefully?
(6 answers)
Closed 2 years ago.
Is it possible to set a specific interpreter (Python 3.7 or Python3.8) without using any IDE but only using command line commands?
I know that is possible using Pycharm, Anaconda or other else, but I would know the command.
Thanks and good day
If you use conda or mini conda, you can set up separate virtual environment with the benefit of selecting a different interpreter version and different packages. I suggest you familiarise yourself with conda and miniconda, and how to start an environment, run scripts etc from terminal with their guides. Resources below:
https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
This question already has answers here:
How can I make a Python script standalone executable to run without ANY dependency? [duplicate]
(19 answers)
Closed 3 years ago.
I have to check versions of different software and their proper patches and I have written a python script that works (developed in my office laptop).
Now I have to run the scripts in my labs and the lab PCs do not have python and I am not allowed to install python on them.
Is there a way to run my python script in the labs?
Options I have seen
Convert my python to an EXE and run it.
If I choose this option, I do not prefer the use of the scheduler to run the EXE in a fixed time as the labs may be used for testing.
How do I create API for my code so I can call the API and run it as needed?
or is there a better way than I have missed?
You could use this alternative way if you dont want to compile to EXE:
For Running Script
Download Portable Python in Folder here
(Optional for additional packeges used) Place venv(Python Virtual Enviroment) in same folder
(Optional) Use venv with python.exe -m venv env
Open cmd in folder with python.exe
Run your script with python.exe script.py
For API:
You can use arguments for API ,it depends how much time and effort you want to put in.
Use sys.args and run script with required arguments
Use TCP Server on allowed ports and listen for commands* (Can be time consuming if you didnt worked with TCP)*
This question already has answers here:
How can I make a Python script standalone executable to run without ANY dependency? [duplicate]
(19 answers)
Closed 3 years ago.
I have a Question about compiling a python script to Executable. So If I compile a C/C++ static executable I know that it will work on other systems without the need of installing some frameworks or stuff. I am really not sure if Python scripts compiled to executable work on other systems without Python installed. So, Is it good and safe to compile python scripts to executable? If I convert a python script to executable and run it on systems without python installed an Error pops up saying Failed to execute script emailmanager
Yes when you compile python using pyinstaller it creates a directory with the compiled executable and all the libraries it needs to run. Therefore you can distribute said directory and it should work on any system - even when python or used libraries are not installed