different PYSTARTUP variables for different python installations - python

We have an in-house developed network-based application that is based on python, it provides a command-line environment in the same way like python does. I also have a local python installation on my machine. Sometimes for simple python tasks, i prefer using my local python install... Is possible to to have a different PYSTARTUP env variable for each of installation?

You can always export PYSTARTUP="whatever" on the shell before starting your script.
You can also put PYSTARTUP="whatever" in front of the command you want to run, e.g. PYSTARTUP="whatever" python something.py

Related

How to get Py4Delphi to use a Python Virtual Environment

I am using Delphi 10.4 to invoke a python script using the Py4Delphi library.
How can I execute the script with respect to a particular python virtual environment directory?
Using the virtual environment is basically setting a few environment variables before running python. You can look into scripts\activate.bat which variables that are.
You don't need to recover those changes after running it, because within a process you're running with a copy of the system environment.

How Can I Execute *nix or BASH SOURCE CODE in Azure Functions?

I have already written Azure Functions in Python, and know there's also official support for other popular dialects - JS, Java, .NET, etc. BUT, I have a special scenario, where I wish to execute some functions originally written in bash, or to be able to access such *nix utilities as calc, sed, awk and more.
I know that Azure Functions are meant to abstract away the server and even environment(?), but is there a way one can still install and run *nix like utilities or for that matter any exes (since *nix can port).
Some ideas am toying with:
include binaries in /bin folder of my python project,
and then invoke it using something like:
from subprocess import call
call(["cal", "-y"])
Problem; Can I do this without having to deploy my own binaries?
TL;DR: How to execute own binaries and access Shell inside Azure Functions?
Obviously, Azure function is running on Windows Server.
After my research, I found that the azure server was pre-loaded with git bash.
You can find the following path on the Kudu:
D:\Program Files (x86)\Git
If you want to run *nix command calc on windows, you need to download calc for Windows execution files and upload it to Kudu.
Then add the current directory to the environment variable.
D:\home\site\mybin>set PATH=D:\home\site\mybin;%PATH%
Please make sure you add your environment variable in front of the variable D: \Windows\System32; so that you can overwrite Windows own calc command.
Verify:
When you execute calc commands in Python, please use the os.environ and os.putenv to set your own environment variables.

Setting default system-wide environment for Python

My company releases part of its product as Python scripts running on an embedded Linux-based system. For our production release, I want to set the environment variable PYTHONOPTIMIZE="1" so that all Python scripts will be run as if the "-OO" switch were specified.
However, the scripts will be running by a user who isn't logged in (for example, some are invoked via the web server and others are started via systemd) so I can't simply set PYTHONOPTIMIZE in, e.g., /etc/profiles.
One solution might be to modify the shebang in each Python script to include the "-OO" switch but this seems a little involved. Is there an obvious way to make Python execute all Python scripts using a default environment that I missed?

Running script in bash from a virtualenv

I am trying to run script in bash from python, but I am currently working in a virtualenv, and when my script calls on a specific program, I get "usr/bin/env: luajit: No such file or directory".
When I run the same script inside a separate bash window (outside the virtualenv), it runs perfectly.
I have a feeling it is because this program is not properly being pointed to, but have no idea how to tell my virtualenv to look for that program.. How do I get around this?
I am on Ubuntu 14.04, using python 2
The answer lies in environment variables. PATH should contain the location where your luajit is.
See setting an environment variable in virtualenv for some ways to automatically set environment variables in a virtualenv (but two of the currently suggested ways require wrappers and one - editing a stock script). There's no magic: virtualenv edition by Allison Kaptur describes the (rather simple) magic behind virtualenv's work so you may be able to find an even better place to put the variable assignment in.

Change python path for a specific python install

I have a full python installation with files in /usr/local/, but also have one that I compiled from source sitting in ~/python_dist. If I look at sys.path on each interpreter I see that they indeed import from different libraries.
Currently I can run $ PYTHONPATH=~/other_py_libs ~/python_dist/bin/python to invoke the custom interpreter with some other modules available in the path. However, I don't want permanently change the global PYTHONPATH variable.
How can I permanently change the python path for only one specific python install?
The easiest way to do this is to use a virtualenv (manage with virtualenvwrapper). With virtual environments you can set up different, isolated python environments (kind of like little python playgrounds). Switching between them (with the help of virtualenvwrapper) is as easy as typing workon envname. You don't have to worry about switching the PYTHONPATH around, and you can direct scripts to use a specific environment simply by running them with the python install in that environment, e.g. using #! /home/myname/.virtualenvs/envname/bin python.

Categories

Resources