pyenv-virtualenv: `3.6.4' is not installed in pyenv - python

This just confuses me and I don't know what it means. I have 3.6.4 installed on my computer(MacOS) but it doesn't want to work.
I can't think of any solution and don't know what to do.

The answer is slightly different wether you are on a Mac or a Linux (I am not that used of Windows for Python working).
Install
(MacOS =>) Be sure that the XCode CLI tools are installed on your computer.
xcode-select --install
Then, to install the virtualenv, you have to enter the following command.
pyenv install 3.6.4
Here, you can have some issues regarding the zlib library that is not available. Nevertheless, the XCode CLI should have installed zlib. So you are good to go (it still has some issues on MacOS Mojave nevertheless).
Create Virtualenv
Then create a new virtualenv for a future use :
pyenv virtualenv 3.6.4 v3.6.4
Check
Check that everything is ok and that the virtualenv is installed through the following command :
pyenv virtualenvs
Use
Then you just have to use it. For instance for a local use :
pyenv local v3.6.4
Check
Check that everything is ok:
pyenv local
and it should show v3.6.4.

Related

How to change python3 version on mac to 3.10.10

I am currently running python 3.9.13 on my mac. I wanted to update my version to 3.10.10
I tried running
brew install python
However it says that "python 3.10.10 is already installed"!
When i run
python3 --version
in the terminal it says that i am still on "python 3.9.13"
So my question is, how do i change the python version from 3.9.13 to 3.10.10? I already deleted python 3.9 from my applications and python 3.10 is the only one that is still there.
I also tried to install python 3.10.10 from the website and installing it. However it does not work. Python 3.10.10 is being installed successfully but the version is still the same when i check it.
Python 3.10.10 is already installed along with Python 3.9.13. Your path is probably pointing to 3.9.13 and that's why you're getting that Python version.
Try modifying your path variable to point to brew's Python installation, or (better yet) make use of a virtual environment.
a) Telling what Python version your PATH variable is pointing to:
$ which python
Will tell you what's the actual executable's path. That way, you are going to see exactly where you main python resides.
b) If you want to create a virtual environment with brew's python try something like:
$ /usr/local/Cellar/python#3.10/3.10.1/bin/python3 -m venv py310
$ source venv/bin/activate
$ python
> # you should be inside a 3.10.1 envornamente
> CTRL+D
$ pip install requests
you can use pyenv to work with multiple python environments
things to do:
install pyenv : brew install pyenv
install particular python: pyenv install 3.10.10
set python3.10.10 to gloabal python env: pyenv global 3.10.10
and can start using python 3.10.10 version
Just delete the current python installation on your device and download the version you want from the offical website. That is the easiest way and the most suitable one for a beginner.

Multiple Python versions in the same Ubuntu machine

I am on an Ubuntu machine, where Python 3.10 is automatically installed. To do a given task in a shared codebase I need to use Python 3.9 for some issues with new versions.
I would like to have both of the Python installed on my machine and be able to use both and switching if I need to.
So, I am trying to install old Python 3.9 with the command sudo apt-get install python3.9 and it succeeded in installation, but I can't find it anywhere even with which python3.9 and similar.
Even the python interpreter option in VSCode does not show it.
I think I am missing something. Can please someone help me? Thank you
Python should be installed under the /usr/bin/ folder. If it's not there, you might have not actually installed the package.
Check out this guide for installing specific versions (Scroll down to the "Use Deadsnakes PPA to Install Python 3 on Ubuntu" section.)
This will allow you to install specific version of python like python3.9
Packages on Ubuntu (usually executables) are installed in the /usr/bin directory. You could try to list all executables under /usr/bin with
ls /usr/bin/python*
This is the easiest way. You could see also what packages are installed
apt list --installed | grep python

Pipenv not recognizing shims for PyEnv python installation

I'm attempting to use pipenv and pyenv to create a virtual environment using python 3.9.0 for a project, but am not able to get pipenv to recognize the version of python 3.9.0 installed by pyenv. Oddly, using pyenv python 3.8.6 works just as expected, and I'm specifying the specific python I want pipenv to use, similar to this answer.
I'm running Catalina 10.15.7 and had a coworker reproduce this exact same behavior on his machine.
Both Pipenv and pyenv have been installed via Homebrew. I have since tried uninstalling homebrew Pipenv and reinstalling with pip, with the same results.
To Reproduce
I successfully ran pyenv install 3.9.0, and when I run pyenv versions, I see:
system
3.8.6
3.9.0
Just as I'd expect.
Inside my working directory, I run pyenv local 3.9.0 to switch my local version of python, followed by pyenv version, which returns returns:
3.9.0 (set by /Users/my-name/myproject)
indicating that the local version was set.
To double check, running pyenv which python returns:
/Users/my-name/.pyenv/versions/3.9.0/bin/python
Now, if I run pipenv install --python 3.9.0 I get the following:
This already is suspect, since 3.9.0 is my local version already. If I respond with y, I get:
Which seems odd, as when I run python, I get to python 3.9.0, so clearly it is on my path. A Pipfile is not created for me, and I don't get a pipenv virtual environment.
Now, if instead I run pipenv install --python $PIPENV_PYTHON, which should in theory use the version of python on my path (which, again, should be 3.9.0), I get this:
Notice how it says "using /users/..../python (3.9.0) to create virtualenv", which is correct, however the next line down says "created virtual environment CPYTHON3.8.6...".
Now, if I repeat the above steps using python 3.8.6, everything works fine.
Additionally, if I specify pipenv --python ~/.pyenv/versions/3.9.0/bin/python3.9, that also seems to work fine -- so for some reason it's not respecting the version, but it is respecting the binary.
The same is true if I run pipenv install --python $(pyenv which python), since it's effectively the same thing as the above command.
For reference my environment vars:
PIP_PYTHON_PATH=/usr/local/Cellar/pipenv/2020.11.15/libexec/bin/python <- perhaps this is a problem?
PIPENV_ACTIVE=1
PIPENV_PYTHON=/Users/myname/.pyenv/shims/python
PYENV_ROOT=/Users/myname/.pyenv
And my $PATH starts with PATH=/Users/my-name/.pyenv/shims:
I do happen to have python 3.8 and python 3.9 installed via homebrew as well, however I'm not trying to use these, and since my path leads off with the shims, I feel like this should not be a problem. Running which python3 and which python both point to the "shims" folder.
Summary
Pipenv is not respecting my pyenv shims, despite the fact that my PYENV_ROOT and my PATH are set correctly. Running pipenv install --python $(pyenv which python) works, specifying a python version does not.
Is this a problem with pipenv, or pyenv, or something that I'm doing?
Per the pipenv docs:
Pipenv by default uses the Python it is installed against to create
the virtualenv. You can set the --python option to $(pyenv which python) to use your current pyenv interpreter.
It was probably using your system python versions rather than your shims

How can I change the Python interpreter in virtual environment (Ubuntu 18.04LTS)?

I always used Anaconda on Windows so far and could set up an environment while choosing which exact Python to use. E.g. conda create -n myEnvName python=3.7
Now, I want to familiarize with Ubuntu 18.04 LTS and use basic Python environments.
So I followed these steps:
Created folder in my home = ~/.venvPython
(a) I think I already had a 2.7 and 3.6 by default on the OS.
(b) I do not remember for sure, I think I had to do this sudo apt-get install python3-venv.
Created environment this way after CD'ing to .venvPython folder ran this: python3 -m venv venv1BigDataPgm2
source ~/.venvPython/venv1BigDataPgm2/bin/activate
Command python --version says: Python 3.6.9
Running whereis Python shows this:
rohit#rohitUb18043LTS:~$ whereis python
python: /usr/bin/python3.6 /usr/bin/python3.6-config /usr/bin/python2.7-config /usr/bin/python3.6m-config /usr/bin/python /usr/bin/python3.6m /usr/bin/python2.7 /usr/lib/python3.8 /usr/lib/python3.7 /usr/lib/python3.6 /usr/lib/python2.7 /etc/python3.6 /etc/python /etc/python2.7 /usr/local/lib/python3.6 /usr/local/lib/python2.7 /usr/include/python3.6 /usr/include/python3.6m /usr/include/python2.7 /usr/share/python /usr/share/man/man1/python.1.gz
My doubts:
Can I specify a Python version directly while creating the environment like with conda?
How do I change this to some other interpreter instead of the 3.6.9?
Do I have to manually install a different Python first, then point it somehow?
Please guide me. Thank you.
Rohit
As far as I can tell the venv standard library appeared in Python 3.3 and was never backported to 2.7.
venv can only create virtual environment for its own version of the interpreter and the virtual environment directory can not be moved to a different location or be renamed. Python 3.foo can not create a virtual environment for Python 3.bar. So it is best to pick the wanted interpreter right from the start.
Since, as shown by the output of whereis python, you seem to already have multiple Python interpreters already installed, you should be able to do something like the following:
$ /path/to/python3.3 -m venv /path/to/my/venvs/venv33
$ /path/to/python3.8 -m venv /path/to/my/venvs/venv38
There seems to be a way to change the Python interpreter associated with a virtual environment (I have not tested it, not sure what the limitations are):
$ /path/to/python3.8 -m venv --upgrade /path/to/my/venvs/venv33
Alternatively use virtualenv which seems to offer a bit more flexibility, but is probably less efficient (its next major release, virtualenv 20, should bring a lot of improvements though).
Ubuntu and other Debian-based systems generally ship whichever Python version was current and deemed sufficiently tested when the release was published; after that, only security updates which preserve the version number but add patches are released (so you might get 3.6.9-123security4 instead of 3.6.9-5 or whatever was current when the release was cut).
If you want to run a specific Python version on one of these platforms, see if you can find an Apt source which provides this version for your system (Ubuntu has a soft underbelly of unofficial PPAs of various repute; Debian has backports) or install it from source yourself. There are add-ons like pyenv which let you do this rather easily, safely, and transparently.
There may also be an existing package which gives you a particular newer version; for example, you can do apt install python3.7 and apt install python3.8 on Ubuntu 18.04, but there are no packages for 3.5 or 3.9. Try apt policy python3.7 to see which specific minor version is available from the Ubuntu package archive.
An alternative to that is to always specify the python version you wish use when running a script.
python3.6 test_script.py
Usually, when I'm on Linux and don't need a specific python3 version, I create native python3 environments.
python3 -m venv myenv
source myenv/bin/activate
But if I need a specific python3 version, I do:
python3.9 -m venv myenv
source myenv/bin/activate
To use a specific python3 version with native environments, you have to install that version using the native package manager (eg. apt).

create virtual environment for python 2.7

I want to install django, but my system which it's os is mac has python 2.6 which can't support django. so I installed python 2.7 but at that time when I typed python in terminal it response the version is 2.6 after searching I change it to python 2.7 where both of them are still on my computer, when I want to install django it still install it for 2.6 so I decide to install virtual environment but when I create a new environment using "virtualenv venv" it produce environment with python version 2.6! I really confused what should I do to create virtual environment with python 2.7?
The short answer is that you can edit the PATH in ~/.bash_profile to make sure that path for python 2.7 is in front of 2.6 version.
It is a good/common practice to not touch the system python on MAC OS and install a latest version using homebrew. After you installed brew you can install python by:
brew install python
Homebrew will take care of the PATH. After that you will be able to install packages and control virtual environments with your 2.7 installation.
You can specify your python interpreter as a prefix to virtualenv_install
Refer to this post: Is it possible to install another version of Python to Virtualenv?
What I mean to say is create a new virtual env with the correct python interpreter by specifying it as such:
mkdir virtualenvs
cd virtualenvs
~/.localpython/bin/virtualenv py2.7 --python=/home/<user>/.localpython/bin/python2.7
(See the stackoverflow post I mentioned)

Categories

Resources