简体   繁体   中英

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM