Git bash uses wrong python, other solutions don't work - python

I've seen a couple solution so far but they don't work. I'm trying to run (in git bash, on windows)
bash scripts/test.sh
But it's supposed to use Python27, and I have that, and Python34. when I type python --version, it tells me it's using Python34. I tried doing
PATH=$PATH:/c/Python27/
But it still tells me I'm using Python34. I know it's in my environment variables, so what am I missing?

$PATH:/c/Python27/ adds /c/Python27/ to the end of your PATH. The directory containing the Python34 executable must be already in your $PATH. So you need to add /c/Python27/ before the other directories listed in $PATH, so it is checked before the directory containing Python34.
PATH=/c/Python27/:$PATH

Related

Run Python script with Automator // why does it only work if I include export PATH=/usr/local/bin:$PATH and what does it mean?

I was trying to run a Python script via Mac's Automator and the command is very straight forward:
"cd /Users/myname/Desktop/project && python3 myprojectapp.py".
However, every time I tried to run it, Automator raised an error such as ModuleNotFoundError. This was however, impossible since I had all libraries (e.g. Pandas) installed and running the command in the Terminal as written above worked flawlessly.
Now, I've read somewhere for a similar problem to just include:
"export PATH=/usr/local/bin:$PATH" before the command and it worked. Now, before I go on with my life, I would like to understand what exactly this extra line does and how it affects Automator to the point of making the script work.
Thank you in advance!
That command basically modifies the environment variable PATH and puts the directory /usr/local/bin before everything that is currently in PATH. However, that command is temporary, and the environment variable PATH is restored when the session closes.
What could be happening is the python you're running in terminal and the python Automator is running are different./usr/local/bin probably contains the same python version as you are using in terminal. Take a look at ~/.bash_profile to see if something similar to export PATH=/usr/local/bin:$PATH is in there.
Another way to check is to type which python in both and see if it points to the same python. You probably have yet another python somewhere in the list of directories in your PATH variable.
It's common to use virtual python environments to keep track of which python is running and to experiment with python without messing with system python. Examples of these include: Anaconda and virtualenv.

change python directory from conda

Recently, I installed miniconda, and because of which, my default python directory seems to have changed to,
/home/user/miniconda3/bin/python
Also, the default version seems to have changed to python 3.7 instead of python 2.7
And I cannot seem to install various libraries like tensorflow.
How do I get my python back to normal?
The miniconda installation has properly added itself to your PATH. You can check whether /home/user/miniconda3/bin is listed when you run
echo $PATH
in a terminal. If so, it most likely added some lines to the bottom of your ~/.bashrc file. Simply remove these lines yourself, and your PATH should be back to normal (save the file and open up a new terminal), meaning that typing e.g. python will give you the system Python.

How can I make my PATH more succinct in ZSH?

I am using ZSH. I was having trouble running the Anaconda package manager commands in my terminal. I found that I could add the bin to my PATH using this code:
export PATH="$HOME/anaconda3/bin:$PATH"
That worked. All of the Anaconda and associated commands work and it left me with this PATH:
/Users/USER/anaconda3/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
But the PATH variable would reset each time I closed the terminal window. After some research, I figured out how modify my .zshrc to make it permanent. I simply pasted this into my .zshrc:
export PATH=/Users/USER/anaconda3/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
All the commands work and are permanent, but aren't I setting myself up for failure down the road? Everything in the PATH, minus the "/Users/USER/anaconda3/bin" were set automatically. What happens when I update Python, for example? How can I include the "USER/anaconda3/bin" portion of my PATH in my .zshrc without being so explicit?
Your PATH concern is not zsh specific. You could organize things differently.
For example, you could decide to add a directory $HOME/bin/ early in your PATH and put inside that $HOME/bin/ symbolic links to the executables (or scripts) that you want to use. BTW, I recommend to have a short PATH (containing some $HOME/bin/ etc...) since it is more efficient and less messy to understand.
What happens when I update Python, for example?
Let's suppose that Python is installed in your system in /usr/bin/python (and that you use some Linux distribution -or some other Unix- with a good package manager dealing with that;on MacOSX consider homebrew). When that file /usr/bin/python is updated, any future exec of it (e.g. by some shell) will use the new version. Read carefully execve(2).
If ou have several Python-s and the one you want to use is under /Library/Frameworks/Python.framework/Versions/3.6/bin and you upgraded it to some Python 3.7 installed under /Library/Frameworks/Python.framework/Versions/3.7/bin you would need to change your PATH.
If you followed my suggestion, you would (for example) just have a symlink from $HOME/bin/python to /Library/Frameworks/Python.framework/Versions/3.6/bin/python and you would upgrade that symlink when installing Python3.7 using for example:
# remove the old symlink
rm -v $HOME/bin/python
# add the new one
ln -sv /Library/Frameworks/Python.framework/Versions/3.7/bin/python \
$HOME/bin/python
In all cases, you are responsible of having a good enough PATH (and preferably a short one).

Remove old Python Installation in MAC OS

I installed python using MacPort and I am satisfied with the result, but found that there are other versions of Python installed in other directories, and can not remember how they were instaldas, it's been five years that use this notebook and perhaps installed by other means a few years.
I tried to remove all references to extra Python, beyond that were installed with MacPorts, but do not think like, I tried to remove the directories with the command rm -rfmas even using sudo rm -rf have success.
The old instalation are in directories:
/System/Library/Frameworks/Python.framework/Versions/
/Library/Python/
How to discover the origin of such facilities and remove permanently?
Don't remove the system Pythons. They may be used by other programs. (I don't know if anything on OS X actually uses them, but it's best to keep them.)
Instead, just make sure that your MacPorts bin directory (at /opt/local/bin) is first on your $PATH.
Don't! The name /Library and /System suggest that they are OS-level directories. Nobody installed them. Instead, Mac and other linux-based systems use them by default for system-level services (and they should not be even manually upgraded or system stability may suffer).
For all what matters, you should just prepend your installation directory to a system variable called PATH in your $HOME/.bashrc file. Then, whenever YOU use python, the system will always search for the first occurrence of python on PATH, which is your python. Open terminal, enter the following command (once in a life time):
echo "PATH={a-path-to-the-folder-containing-your-executable-python}:\$PATH" >> $HOME/.bashrc
To explain it, the quoted command prepends your installation directory as the first place to search for executable files. The >> $HOME/.bashrc write this command to the last line of .bashrc, which is a file that setup your terminal environment automatically upon login.

/bin/env: python: No such file or directory (Windows through Git Bash trying to install new Parse Cloud Code)

Trying to install python from the link here does not seem to give access to the python command in Msysgit... following the instructions here, does not actually say how to get python to work as needed.
Current error when running parse new project_name is:
/bin/env: python: No such file or directory
I believe it's likely because it installed it at C:\Python... anyone know how to fix this?
This error means that Git Bash does not know where your python.exe is. It searches your normal windows search path, the PATH environment variable. You're probably failing the 4th step on the instructions already "Make sure Python is working in the Git Bash":
$ python --version
sh.exe: python: command not found
To fix that, append C:\Python (or wherever you installed python) to your PATH environment variable in windows (instructions here). You need to restart the bash after this for the change to take effect. This will allow you to run python from the windows command prompt as well.
C:\> python --version
Python 2.7.2
If you don't want to alter your windows PATH variable or make python only available to git bash, you could create a .bashrc file in your %USERPROFILE% directory and set the variable there:
C:\>notepad %USERPROFILE%\.bashrc
and add
export PATH=/c/Python:$PATH
to the file. That script is executed every time you start the git bash and prepends C:\Python to git bash's PATH variable, leaving the system-wide PATH variable untouched.
Now that you know what has to be done, you can use this shortcut on the bash instead (appends the export command to your .bashrc)
$ echo export PATH=/c/Python:\$PATH >> ~/.bashrc
Hmmm. If you're using Python 2.7 like the instructions say to, you could try instead of that doing "C:/Python27/python.exe" insted of "python".
I think you can add the location of the python.exe in the PATH environment variable. Follow the steps: Go to My Computer->Right click->Properties->Advanced System Settings->Click Environmental Variables. Now click PATH and then click EDIT. In the variable value field, go to the end and append ';' (without quotes) and then add the absolute path of the .exe file which you want to run via Git-Bash.
don't know if this could be your issue, but its always worth a check.
check your python path is set correctly?
computer->properties->advanced system settings-> environment variables->system variables->PYTHONPATH, value = C:\PYTHON20;C:\PYTHON20\DLLS;C:\PYTHON20\LIB;C:\PY THON20\LIB\LIB-TK

Categories

Resources