Specify which version of Python runs in Automator? - python

In my terminal and in CodeRunner my Python is updated to 2.7.6 but when I ran a shell script in the OSX Automator I found that it is running 2.7.2
How can I update the Automator Python to 2.7.6 like the rest of my compilers ?

I couldn't specify explicitly which python for it to use.
So, I ran it in bash environment with following command:
$ your/python/path /path/to/your/python/script.py
And make sure first line of your python program contains the path to the python environment you wish to use.
Eg:
#! /usr/local/bin/python

Related

Simulate python3 shell commands behavior in windows powershell

I work on an api that run python3 scripts like python3 <scriptname.py>. This api initially run on a linux system. Unfortunately I make the local development of it on a windows. Is there a way to simulate this behaviour so that when I run in powershell python3 -V it give me the version of python.
I have allready python 3 installed on my computer. I tried to add the path to my python.exe to the system variables with for variable the string python3. But after registering and restarting powershell and type python3 -V I still get the error that «python3» is not recognized as a command applet name.
Does anyone have any ideas?
Once python is in your path, you can define a PowerShell alias for python3.
PS > New-Alias python3 python
PS > python3 -V
python 3.6.5
In order to have this alias as a permanent one, refer to this question: Permanent PowerShell Aliases.
I found tricky solution.
Once python is in your path, go to python installed path and copy python.exe and named duplicated one as python3.exe

Shell is selecting Python 2.7, but not 3.7

I have Python 3.7 and I had a Python 2.7.
But when I am using Python Launcher it uses 2.7 not 3.7.
How to use Python 3.7? OS - Mac OS.
If you want python 3.7 as default when you run command python in terminal, you can add an alias in ~/.bashrc
alias python=python3.7
bashrc is a shell script that bash runs whenever it is started interactively. You can find bashrc in your home directory.
In the Python Launcher menu, go to Preferences. You should see a text box called "Interpreter", in there insert the path to your python 3.7, for example:
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
You might also add that to your PATH environment variable and use python3 (and idle3) rather than plain python.
There are several ways you can obtain this behavior, my preferred one is symlinking the python3 executable to python
sudo unlink /usr/bin/python
sudo ln -s /usr/bin/python3 /usr/bin/python
Another way would be using pyenv https://github.com/pyenv/pyenv
Be aware od the fact that if you do this and you have some scripts on your machine that use the shebang #! /bin/python and were written for py2, they may stop working

Can a virtualenv created on Windows be used from WSL bash?

I'm using Windows Subsystem for Linux (WSL) for a test project (obeythetestinggoat) and had a ton of issues trying to get virtualenv to work from the shell or CMD to ensure I was using the latest Python version installed (3.6).
mkvirtualenv --python="C:\Program Files\Python36\python.exe" superlists
I can get both bash and CMD running the virtualenv, but both report different versions of Python.
CMD:
python -V
Python 3.6.0
Bash:
python -V
Python 2.7.6
python3 -V
Python 3.4.3
Since the venv was created with the CMD shell, I would think it would control the version used, and the Scripts folder shows python36.dll, so assume it should be 3.6.
So it seems like the Bash WSL environment is controlling what version is used, regardless of any ENV paths I set. I think I might ditch the Windows approach and go use my Ubuntu install, but really want to understand what is happening here, especially in regards to the virtualenv as it seems to negate the purpose of it all if the shell is only using what came with it and will not use the version supposedly in the virtual env. Any help would be appreciated!

How to load non-default version of python in command line

I have 2 different versions of python installed on my system i.e. 2.6.6 and 2.7.9.
I am running python scripts on linux via QTP(using paramiko on windows). I execute the following sample of code to execute commands.
"python /dir/of/frameword/ somecode"
When I hit this command the default version of python is used to create the shell that is 2.6.6
Is there any way that I could instruct the linux to pick up 2.7.9 with a command like "python27".
I have also added an alias in ./bashrc but that also dosent help.
set up a shell alias
alias python=/usr/local/bin/python2.7
PS:have you run source ~/.bashrc after save ~/.bashrc?I noticed you mention ./bashrc instead of ~/.bashrc,is it a spelling mistake?
use virtualenv

Python 3 installation on windows running from command line

Just curious, is there a particular reason why Python 3.x is not installed on Windows to run default with the command line "python3", like it does on Mac OSX and Linux? Is there some kind of way to configure Python so that it runs like this? Thanks.
EDIT: Just to add, the reason I am asking is because I have both the Python 2 and 3 interpreter installed on my computer, and so it is ambiguous, as both are run using the command "python".
the reason I am asking is because I have both the Python 2 and 3 interpreter installed on my computer, and so it is ambiguous, as both are run using the command "python".
To run Python 2 executable:
C:\> py -2
To run Python 3 executable:
C:\> py -3
where py is a Python launcher that is bundled with your Python 3 installation.
py recognizes the shebang (e.g., #!/usr/bin/env python3 causes Python 3 executable to be run), it respects virtualenv (if you run py without specifying the explicit python executable version) i.e., run:
C:\> py your_script.py
and the correct python version is used automatically -- you don't need to specify the Python version on the command-line explicitly.
is there a particular reason why Python 3.x is not installed on Windows to run default with the command line "python3", like it does on Mac OSX and Linux?
OSX and Linux have python executable installed by default as a rule and it refers to Python 2 version in most cases at the moment that is why you need a separate python3 name there.
There is no Python on Windows by default. And therefore any version that you've installed is just python (I guess). The recommended way to manage multiple python versions is to use the Python launcher.
Is there some kind of way to configure Python so that it runs like this?
If you want to type python3 some_script.py instead of py some_script.py or even just some_script (assuming .py is in %PATHEXT% and Python launcher is configured to run Python scripts (check assoc .py and ftype Python.File) -- the default) then create a bat-file e.g., python3.cmd and put it in %PATH%:
"C:\path to\Python 3.X\python.exe" %*
You likely missed the checkbox at the bottom of the installer.
Full documentation here: https://docs.python.org/3/using/windows.html
Then, I think you just run python, not python3 from the Command Prompt. The reason Unix systems have python3 is because python defaults to Python2.x in many systems.
You have to add the python bin folder to your path. You can do it manually but when you install python i remember you have an option to do that.
I work with multiple Python 2.x and 3.x distros on Windows. Some of them are "portable" - i.e. not recorded in the Windows registry, and therefore not accessible by the version-selector py.exe delivered with Python 3.3+. To save my sanity, I wrote SelectPython.bat which is available on bitbucket. It configures the PYTHONHOME, PYTHONPATH and PATH variables according to the target you give it (a relative or absolute path to the parent directory of python.exe). You can do so in a way that is sticky for the rest of your command-line session:
> SelectPython C:\Path\To\Desired\Version\Of\Python
> python
or transiently, i.e. to call a particular python command without otherwise affecting the environment of the shell you're calling it from:
> SelectPython C:\Path\To\Desired\Version\Of\Python python -c "import sys;print(sys.version)"
You may find it helpful.

Categories