Virtual Env created using pipenv cannot find the env/bin/python

Viewed 45

I have recently upgraded from Ubuntu 20 to Ubuntu 22. In the process, I upgraded from python3.8 to pytohn3.10. This upgrade broke my virtual envs. Hence I am creating new virtual envs using python 10. However when I try to create a new virtual env I get following error.

$ pipenv shell
/home/sk/.local/lib/python3.10/site-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: 1.1build1 is an invalid version and will not be supported in a future release
warnings.warn(
/home/sk/.local/lib/python3.10/site-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: 0.1.43ubuntu1 is an invalid version and will not be supported in a future release
warnings.warn(
Creating a virtualenv for this project...
Pipfile: /mnt/evo/sk/git/vh/Pipfile
Using /usr/bin/python3 (3.10.4) to create virtualenv...
Creating virtual environment...created virtual environment CPython3.10.4.final.0-64 in 83ms
creator CPython3Posix(dest=/home/sk/.local/share/virtualenvs/vhl-J_rX2UKk, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/sk/.local/share/virtualenv)
added seed packages: pip==22.2.2, setuptools==65.3.0, wheel==0.37.1
activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
Successfully created virtual environment! 

Traceback (most recent call last):
  File "/home/sk/.local/bin/pipenv", line 8, in <module>
    sys.exit(cli())
  File "/home/sk/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/home/sk/.local/lib/python3.10/site-packages/pipenv/cli/options.py", line 57, in main
    return super().main(*args, **kwargs, windows_expand_args=False)
  File "/home/sk/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/home/sk/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/sk/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/sk/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/sk/.local/lib/python3.10/site-packages/pipenv/vendor/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/home/sk/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/sk/.local/lib/python3.10/site-packages/pipenv/cli/command.py", line 398, in shell
    do_shell(
  File "/home/sk/.local/lib/python3.10/site-packages/pipenv/core.py", line 2533, in do_shell
    ensure_project(
  File "/home/sk/.local/lib/python3.10/site-packages/pipenv/core.py", line 526, in ensure_project
    ensure_virtualenv(
  File "/home/sk/.local/lib/python3.10/site-packages/pipenv/core.py", line 459, in ensure_virtualenv
    do_create_virtualenv(
  File "/home/sk/.local/lib/python3.10/site-packages/pipenv/core.py", line 964, in do_create_virtualenv
    project._environment = Environment(
  File "/home/sk/.local/lib/python3.10/site-packages/pipenv/environment.py", line 80, in __init__
    self._base_paths = self.get_paths()
  File "/home/sk/.local/lib/python3.10/site-packages/pipenv/environment.py", line 391, in get_paths
    c = subprocess_run(command)
  File "/home/sk/.local/lib/python3.10/site-packages/pipenv/utils/processes.py", line 75, in subprocess_run
    return subprocess.run(
  File "/usr/lib/python3.10/subprocess.py", line 501, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/lib/python3.10/subprocess.py", line 966, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.10/subprocess.py", line 1842, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/home/sk/.local/share/virtualenvs/vhl-J_rX2UKk/bin/python'

Here are details of my python, pip, pipenv.

$ which python3; python3 --version; which pip; pip --version; which pipenv; pipenv --version
/usr/bin/python3
Python 3.10.4
/usr/local/bin/pip
pip 22.2.2 from /home/sk/.local/lib/python3.10/site-packages/pip (python 3.10)
/home/sk/.local/bin/pipenv
/home/sk/.local/lib/python3.10/site-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: 1.1build1 is an invalid version and will not be supported in a future release
warnings.warn(
/home/sk/.local/lib/python3.10/site-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: 0.1.43ubuntu1 is an invalid version and will not be supported in a future release
warnings.warn(
pipenv, version 2022.9.8
1 Answers

I resolved the error by doing

  • Uninstall pip (pip uninstall pip)
  • Remove the local packages for python3.10 in .local folder
  • install pip again using sudo apt install python3-pip
  • Here checked pip is using python3.10.
  • Then I did pip install pipenv.
  • Then I did pipenv shell and it worked.
  • I checked that the /home/sk/.local/share/virtualenvs/vhl-J_rX2UKk/bin/python was present after creating environment.
Related