4

I would like to have two virtual environments, where one has a version of python 3.6 and the other has a version of python 3.7. This will allow me to hopefully complete my projects without conflicting needs when installing modules and packages. Tensorflow I believe can't be done in 3.7.

I have tried pipenv shell w/ 'pipenv install Django==3.0.2', github advice,

Some sites say to use a Python, pipenv shell, DJango combo but this appears to only create one version of a python3 virtual environment, and the previous existing virutalenv will be removed. Should I create a new Pipfile to prevent this, or are Pipfiles not designed for this configuration.

  1. Github discussion link:

https://github.com/pypa/pipenv/issues/1071

setup environments
pipenv --name 35 --python 3.5 install 
pipenv --name 36 --python 3.6 install  
# run commands 
pipenv --name 35 run python

I tried to follow up with these advised coding procedures and I got ModuleNotFoundError: No module named 'apt_pkg'.

  1. Lastly I have considered pyenv, yet this appears to be tailored for mac users. I have a Windows 10 computer so I am not sure if this will work. I used "$pip install pyenv-win"
$ pip install pyenv-win
Defaulting to user installation because normal site-packages is not writeable
Collecting pyenv-win
  Using cached pyenv_win-1.2.4-py3-none-any.whl (25 kB)
Installing collected packages: pyenv-win
Successfully installed pyenv-win-1.2.4

But am not able to create any virtual environments with it:

$ pyenv-win versions
ModuleNotFoundError: No module named 'apt_pkg'

Note: part 3 followed these guidelines

Any help is appreciated. I really would like to get this working.

Mitchell Lee
  • 41
  • 1
  • 2
  • Have you tried to use `virtualenv` ? [Here](https://stackoverflow.com/questions/41573587/what-is-the-difference-between-venv-pyvenv-pyenv-virtualenv-virtualenvwrappe) you can find a good explanation about all the other options to create virtual environments. – Brad Figueroa Jul 11 '20 at 20:18
  • I was able to and it worked. Thank you Brad! – Mitchell Lee Jul 15 '20 at 03:43

2 Answers2

0

After installing pyenv-win via pip don't forget to set the default environmental variables to your user (see installation doc in https://github.com/pyenv-win/pyenv-win):

[System.Environment]::SetEnvironmentVariable('PYENV',$env:USERPROFILE + "\.pyenv\pyenv-win\","User")
[System.Environment]::SetEnvironmentVariable('PYENV_HOME',$env:USERPROFILE + "\.pyenv\pyenv-win\","User")
[System.Environment]::SetEnvironmentVariable('path', $HOME + "\.pyenv\pyenv-win\bin;" + $HOME + "\.pyenv\pyenv-win\shims;" + $env:Path,"User")

Also, I think after restarting your terminal you can invoke pyenv-win by just typing pyenv.

0

To create virtual environment with pyenv , you need first to install the versions and then set it locally for your project or use the global version that you set.

to install a python version you need to execute :

pyenv install 3.8.2
pyenv local 3.8.2

But if you are going to use pyenv in combination with pipenv I recommend you do the following :

pipenv install --python 3.8.2

if you have pyenv install pipenv will do the following :

  1. if 3.8.2 is your current installed version it will use it
  2. if not, it will use pyenv to install it and set it for this virtual environment
Dharman
  • 30,962
  • 25
  • 85
  • 135