How to change default install location for python? - python

I am using RedHat Linux.
Python 2.6 is already installed in usr/src/bin. When I install Python 2.7, it gets installed in usr/local/src/bin.
Further, I need to install sklearn. When I try installing sklearn using pip, it refers to Python2.6 and not Python2.7.

You can run python -m pip to see if pip is using the right version of python
I think you can probably specify the location with usr/local/src/bin pip install If you're sure that's where python 2.7 is installed. If pip is not using python 2.7 you should reinstall pip in the correct version.
There is another question which could help solve yours:
Pip Install not installing into correct directory?

Related

Python pip installing problem in ubuntu libux

I have installed python 3.9 in Ubuntu, because it comes with python 3.8 which is an older version.
I changed the command for terminal alias python 3 = python 3.9, but when I installed pip, it installed for python 3.8 and after that when I am using pip install to install python packages, it installs for python 3.8. How can I fix it?
try with pip3 install
This kind of issue even happened to my case when I was working with the python modules recently on my project. Try this out it worked for me.
Due to variations in the installation process of python, pip often requires different ways to access for different people. A few examples that may help you include pip3 install, py pip install py -3 pip install or python3 pip install. Usually one of these works for me.

How to use pip for python 3.9 instead of inbuilt python 3.8 in Ubuntu?

Today I faced a problem regarding pip3 in Ubuntu. Ubuntu comes with python 3.8 but I wanted to use latest versions of python, like 3.9 or maybe 3.10. So I installed it using 'ppa:deadsnakes' repository and also installed pip. But the problem is I want to use pip in python 3.9 instead of version 3.8. So I changed the default python version to 3.9 and everything crashed.
So reverted to python 3.8. Whenever I install some package it gets installed using python 3.8.
Help me, how can I use python 3.9 pip and install packages in python 3.9 without changing the default version.
Any help is appreciated.
--> Thing I want is that when I want to install python package using
pip3 install <package_name> it must install in python3.9 and not in python3.8
You don't need to install pip separately
You should be able to refer to it as such
python3.9 -m pip install
Hello everyone I fixed my issue.
The problem is we cannot override default python version in Ubuntu as so many things depend on it.
So I just made an alias as : alias pip3='python3.9 -m pip' and alias for python : alias python3='/usr/bin/python3.9'
If anyone face this issue please do what I specify and you will be good to go.
Now all my packages are being installed in python3.9.
Currently all python3 versions are using the same pip version which can be installed by:
sudo apt-get install python3-pip
The easiest way to work with a specific python version is creating a virtualenv and working under it. When working with a virtualenv you can use pip freely without worrying about which python version it belongs.
you can use pip for python3.9 by pip3.9 install <package-name>

AWS cloud9 pip install goes to python 2.7 instead of 3.6

this question is specifically for aws cloud9. Everything looks fine prima-facie, but it's creating a lot of problems.
When i am checking python version, it's showing the correct version (without using python3)
xxxx#yyyyy.zzz:~/environment $ python --version
Python 3.6.8
When i am using which python, it's showing the correct (desired) python version
xxxx#yyyy.zzz:~/environment $ which python
alias python='python36'
/usr/bin/python36
When i am checking pip version, it's showing pip version for python 3.6, but showing a very old version of pip.
xxxx#yyyy.zzz:~/environment $ python -m pip --version
pip 9.0.3 from /usr/lib/python3.6/dist-packages (python 3.6)
When i try to upgrade pip to new version, it goes to python2.7 now (undesirable)
xxx#yyyy.zzz:~/environment $ pip install --upgrade pip
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Defaulting to user installation because normal site-packages is not writeable
Requirement already up-to-date: pip in /usr/local/lib/python2.7/site-packages (20.0.2)
so, when i do a pip install of a desired package, it gets installed, but cannot use it in my program as it installs for python 2.7.
I have gone past this issue on my local windows computer a long time ago. However, this is a ec2 default environment that comes when setting up cloud9, and is a linux ubuntu dist (afaik).
Have tried to find out online, but couldn't get a simple answer. I could find answers relating to using virtualenv for these kind of issues. I am wondering if there is a simpler solution to this.
I finally resolved it by unaliasing "python" with python36.
unalias python
Then when i went to ask python version, it gave python 2.7 (as expected)
then i went for
sudo python3 -m pip install --upgrade pip
it finally worked and upgraded pip to latest.
then i could download other libraries using
python3 -m pip install <library-name>
Thanks Arun for your extensive help.
This solution may be a workaround, but it finally made it work. If anyone wants me to find the solution further, i am ready to engage.
python is an alias to point to python36. Looks like you have python 2 and python 3 installed.
python -m pip --version is returning the pip version pointing to python3 because python here refers to python3. If you try python2.7 -m pip --version it will return the pip version corresponding to python2.7
You should rather check pip --version to see the version of pip.
You could install your packages using pip3 install <package-name> or set an alias for pip to point to pip3
which pip3
Once you get the path of pip3, then you can create the alias
alias pip=`<path to pip3>

brew python versus non-brew ipython

I installed python via brew, and made it my default python. If I run which python, I obtain /usr/local/bin/python. Also pip is installed via brew, which pip returns /usr/local/bin/pip.
I do not remember how I installed ipython, but I didn't do it via brew, since when I type which ipython, I obtain /opt/local/bin/ipython. Is it the OS X version of ipython?
I installed all libraries on this version of ipython, for example I have matplotlib on ipython but not on python. I do not want to re-install everything again on the brew python, rather continue to install libraries on this version of ipython. How can I install new libraries there? For example, Python Image Library, or libjpeg?
If possible, I would like an exhaustive answer so to understand my problem, and not just a quick fix tip.
I installed python via brew, and made it my default python. If I run which python, I obtain /usr/local/bin/python.
Okay, good so far.
Also pip is installed via brew, which pip returns /usr/local/bin/pip.
Actually, not quite brew install python would have installed pip because even doing brew search pip comes up with this warning.
If you meant "pip" precisely:
Homebrew provides pip via: `brew install python`. However you will then
have two Pythons installed on your Mac, so alternatively you can install
pip via the instructions at:
https://pip.readthedocs.io/en/stable/installing/
So, Python came with pip, not brew install
when I type which ipython, I obtain /opt/local/bin/ipython. Is it the OSX version of ipython?
There is no "OSX version of ipython"...
I installed all libraries on this version of ipython, for example I have matplotlib on ipython but not on python.
You actually did install them to your brew installed Python. IPython is not a new installation of Python.
You can even start a python interpreter from the terminal and import matplotlib to check this
I do not want to re-install everything again on the brew python
What exactly needs re-installed? It's already installed into the brew python
To transfer all your packages you can use pip to freeze all of your packages installed in ipython and then install them all easily from the file that you put them in.
pip freeze > requirements.txt
then to install them from the file pip install -r requirements.txt
I'm not entirely sure if I understood what you're asking so if this isn't what you want to do please tell me.
OK, so I solved by uninstalling macport (and so the ipython I was using, which was under /opt/local/bin) and installing ipython via pip. Then I re-install what I needed (e.g. jupyter) via pip.

Install python module for non-default version on linux

I have different python versions installed on my ubuntu machine. The default version is 2.7.
So when I install any new python module, for example using:
#apt-get install python-nfqueue
it will be istalled just for the default version (2.7)
How can I install the new modules for the other versions?
Is there a way to do it using apt-get install?
Thank you!
You should install Python libraries with the Python package installer, pip.
Create a virtualenv with the Python version you want to use, activate it, and do pip install NetfilterQueue. You'll still need to install the system dependencies (eg libnetfilter-queue-dev in this case) with apt-get.
You can install pip to work with different versions of python. Here is a link to the pip read the docs page(http://pip.readthedocs.org/en/latest/installing.html).
to install pip to the default version of python on your machine:
python get-pip.py
to install for non standard versions call python with the version you wish to install for:
python33 get-pip.py
you can then run pip for python version 3.3 by calling
pip33 install pythonmodule

Categories

Resources