问题
On my MacBook Pro, I have Python 3.6 as default but the project I take over from another requires 2.7, which I have it installed via Anaconda. I set up the Pipenv using pipenv install
which setup a version to 3.6. Then I tried to change the version by :
pipenv --python 2.7
but it returned this warning:
Warning: Your Pipfile requires python_version 3.6, but you are using 2.7.15 (/Users/j/.local/share/v/Z/bin/python).
Then of course pipenv check
failed, and returned:
Specifier python_version does not match 3.6 (2.7).
Then I tried pipenv install python 2.7.15
and also failed. The Pipfile remains as 3.6 unchanged.
Error: An error occurred while installing 2.7.15!
Could not find a version that satisfies the requirement 2.7.15 (from versions: )
No matching distribution found for 2.7.15
Here is the python versions ls -ls /usr/bin/python*
32 -rwxr-xr-x 1 root wheel 66880 24 Oct 12:47 /usr/bin/python
0 -rwxr-xr-x 4 root wheel 925 18 Aug 02:45 /usr/bin/python-config
0 lrwxr-xr-x 1 root wheel 75 8 Oct 21:45 /usr/bin/python2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
0 lrwxr-xr-x 1 root wheel 82 8 Oct 21:45 /usr/bin/python2.7-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
32 -rwxr-xr-x 1 root wheel 66880 24 Oct 12:47 /usr/bin/pythonw
0 lrwxr-xr-x 1 root wheel 76 8 Oct 21:45 /usr/bin/pythonw2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7
Please advice how I can switch the python from 3.6 to 2.7 for this particular project using Pipenv?
All the best,
Jiajun
回答1:
The command you tried pipenv install python 2.7.15
is wrong for multiple reasons.
First of all, the format of the command pipenv
is the following
pipenv install <package> <package>...
So when you run pipenv install python 2.7.15
you just tried to install two packages called respectively python
and 2.7.15
, which obviously is not what you wanted to do.
Even if you used the correct syntax pipenv install python==2.7.15
that would be wrong since you would be installing python 2.7.15 inside another python environment with python 3.6 installed (your system version on your laptop).
If you want to install multiple versions of Python in the same environment (read as your laptop) and don't messup with the system versions, you should use something like "pyenv" (https://github.com/pyenv/pyenv). Pyenv works very well with pipenv
.
You will be able to install Python 2.7.15 with this command
pyenv install 2.7.15
As you can see this is different from the command you already tried pipenv install python 2.7.15
.
Also since you have been having issues with your Pipfile, I would suggest to move that file together with Pipfile.lock in another directory (for backup purposes) and start from scratch with an empty directory.
Also as suggested here https://pipenv.readthedocs.io/en/latest/ it is better to create an empty folder ".venv" inside your root folder where all the python dependencies from that virtual environment will be installed.
So the correct list of commands to run is
pyenv install 2.7.15
mkdir .venv
pipenv --python 2.7.15
pipenv install <package>
I hope this solves your issues
来源:https://stackoverflow.com/questions/53676585/cant-switch-python-version-on-pipenv