How to set python path with git bash in windows? - python

Using Git Bash on Windows 10.
python version: 2.7.12
When run pip, it shows:
$ pip
bash: /c/cygwin/bin/pip: /usr/bin/python2.7: bad interpreter: No such file or directory
How to find the right python path with pip?
Addition
$ which python
/c/cygwin/bin/python

Your pip is somehow using the wrong path for your python that doesn't exist. However, there is a simple workaround, you can type this to specify the python interpreter you want to use:
$ /c/cygwin/bin/python -m pip install yourpackage
This is only a temporary workaround, to fix it, try something from this question.

Related

VS Code can't find python 3 interpreter

I am installing Python 3.7.2 for the first time, and I'm using the VS Code python extension.
When I run python -V I get Python 2.7.10 which is not correct!
When I select the usr/local/bin/python3 interpreter in VS Code I get this error when running a script:
bash: /Users/erik/Work/Python/usr/local/bin/python3: No such file or directory
But when I look in usr/local/bin I can see that Python3 is there. I'm not sure why VS Code pastes the work directory in front of usr/local/bin ?
My first thought was that Python3 should be in the PATH variable so I ran the included Update Shell Profile command, which gives this feedback:
This script will update your shell profile when
the 'bin' directory of python is not early enough
of the PATH of your shell.
All right, you're a python lover already
Now, after rebooting VS Code I get a new option for selecting an interpreter:
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
Is that different from the Python in usr/local/bin ? When I select it, I get this error:
The script isort is installed in '/Users/erik/Library/Python/3.7/bin' which is not on PATH.
I also get this sideways related error:
You are using pip version 18.1. You should consider upgrading via the 'pip install --upgrade pip' command.
But, when following these instructions I get yet another error:
bash: pip: command not found
All in all, this process and the official documentation seem less than user-friendly? Apparently I'm required to dig deep through my mac's system files in the terminal before even writing one line of code.
Am I missing an essential step here?
I suggest that you use virtual environment for your project
first
pip install virtualenv
open cmd in your project directory that you open in VS-Code (it's important that vs-code sees this virtualenv folder that we will create)
mkvirtualenv my_env
and it will activate it automatically. if not run
my_env/bin/Scripts/activate or my_env/Scripts/activate
Then go open vs-code then select my_env for python interpreter
Well, if you want to change your default Python version for the whole system, it might break some applications that are depending on Python 2.
You can alias the commands by adding this line to your ~/.bash_profile:
$ alias python='python3'
The python command will now refer to python3.
If you want to execute the original Python (which refers to python2), you can escape the alias (so \python will launch python2 without touching the alias).
Btw.
$ unlink /usr/local/bin/python
$ ln -s /usr/local/bin/python3.7 /usr/local/bin/python
could also be a workaround for you.

Python installation in custom directory (Linux): PIP not working

I have installed Python3.6.4 in a Linux machine, under a user directory, lets say /drive/username/Python3.6.4
I've setup my path and aliases, and Python is working properly (i.e. executing python3 puts me in the correct environment, which python3 produces: /drive/username/Python3.6.4/bin/python3)
The problem is with pip!
When i execute pip3, i am getting:
-bash: /username/Python3.6.4/bin/pip3: /usr/local/bin/python3.6: bad interpreter: No such file or directory
the command which pip3 gives: /drive/username/Python3.6.4/bin/pip3
What am i missing?
On my PC:
$ cat /usr/bin/pip3.6
#!/usr/bin/python
...
So, I think your pip has shebang like #!/usr/local/bin/python3.6.
Try rewrite or:
/drive/username/Python3.6.4/bin/python3 -m ensurepip
it will make correct pip in /drive/username/Python3.6.4/bin directory.

brew install python installs python2

I have 3 versions of python installed on my Mac. 2 of them are through brew i.e. python2 and python3 while the native version is python. the problem is when I put brew install python it installs python2 and not python. (By saying python means the version which runs on putting that command in terminal). What should I do so that if I type python my brew installed python launches.I have my path variables set correctly and the brew installation path is ahead than that of the usr/bin The problem I am encountering is that I have nltk installed through pip, pip2 and pip3 and when I import nltk in python2 and python3 there is no problem but when I do that in python it show no module found.
Try which python in a terminal to see which python will run. Then you know and can act accordingly to fix it.
ls -lsa $(which python) will let you see if it is a symlink to another location or a real executable. if a Symlink you can see where it points to and so you can follow the breadcrumbs to the final binary used.
if you run python from a terminal and in the python REPL do the following
import sys
print sys.path
you can see to which site-packages locations are pointed.
Other than that you of course have the option to use virtual environments to set up your version of python
if you really want python2 to be the default python command you can add a symlink to your ~/bin folder (create it if it does not exist)
mkdir ~/bin
cd ~/bin
ln -s $(which python2) python
chmod +x python
and make sure that export PATH=~/bin:$PATH is added at the back of your .bashrc or .profile or .zshrc file
Now start a new terminal session and try out python again it should point to brews version
Hope that helps

virtualenv can't find python2

I'm on a mac, which comes with python 2.7 installed, so I should have the required version.
At least, I believe that's the problem. I'm getting an error when trying to run make install for a project, and getting the following error:
The executable python2 (from --python=python2) does not exist
make: *** [bin/python] Error 3
virtualenv --python=python3 fibonacci_env
Point out which python
Specify the full path to the Python interpreter (not sure if this is the right path - haven't used MacOs):
mkvirtualenv myenv --python=/Library/Frameworks/Python.framework/Versions/2.7/bin/python
or smth like:
--python=$(which python)
Python 2.7 is part of system framework and is located here:
/System/Library/Frameworks/Python.framework/Versions/
If you want to create a virtualenv with python2.7 on macOS Sierra do this:
virtualenv -p /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python my_venv
Specify the python version you want to use
virtualenv -p /usr/bin/python3 venv

How to use pip with multiple instances of python

I recently installed python3 only to realize that mysql-python as well as many other modules were not well supported with it yet. So I changed the path in my bashrc file to point to an installation of python 2.7. The problem is that when I installed python 3 I also installed distribute and pip along with it. I removed the pip and distribute files from the python3 bin directory and installed setuptools and pip using python 2.7 however now when I use the pip command to install django and mysql-python, I get a bash error python331/bin/pip No such file or directory. It's still looking for pip in the python3 install. How can I remedy this?
Thanks
...I get a bash error python331/bin/pip No such file or directory.
It's still looking for pip in the python3 install. How can I remedy
this?
bash, by default, hashes the locations of commands to avoid searching $PATH each time, so if, when you execute...
$ type pip
...you get something like...
pip is hashed (python331/bin/pip)
...you just need to clear the hash table for bash with...
$ hash -r
...then it'll pick up the version in Python 2.7 the next time you try to run pip.
Fixed it.
Renamed the directory of where the python3 was installed, bash automatically looks for the next available python install python 2.7

Categories

Resources