Imtiaz Ahmed
Imtiaz Ahmed

Reputation: 323

Pipenv is throwing error and not creating virtual environment

I've reviewed other Pipenv-related questions, but none matched my specific issue. I'm using Ubuntu 20.04 with Python 3.8 and Pipenv 11.9.0, which was functioning properly.

However, when I encountered trouble installing a package, I decided to update both Python and Pipenv. I installed Pipenv 2023.6.18, but I couldn't use it because the "--version" command still displayed the old version, and the virtual environment continued to be created with Python 3.8.

To address this, I followed the instructions in the Pipenv documentation on selecting a specific Python version for virtual environment creation. By running the command pipenv --python 3.11 a virtual environment was created with Python 3.1 not 3.11

I verified the contents of my ~/.local/bin directory and found two files: autopep8 and pycodestyle.

autopep8 contains this code:

#!/bin/python3.9
# -*- coding: utf-8 -*-
import re
import sys
from autopep8 import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

pycodestyle contains:

#!/bin/python3.9
# -*- coding: utf-8 -*-
import re
import sys
from pycodestyle import _main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(_main())

After running this command to update pipenv again:

pip install --user --upgrade pipenv

I ended up messing it up completely. I am now unable to create and activate the virtual environment as I could before.

Then I uninstalled pipenv with this command: pip uninstall pipenv and it uninstalled the latest version.

Now checking pipenv --version throws this:

/usr/bin/pipenv:6: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  from pkg_resources import load_entry_point
pipenv, version 11.9.0

pipenv shell throws this error:

user@user:~/Desktop/Test-ML$ pipenv shell
/usr/bin/pipenv:6: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  from pkg_resources import load_entry_point
Shell for UNKNOWN_VIRTUAL_ENVIRONMENT already activated.
No action taken to avoid nested environments.

Here are some files from various directories that could be helpful in identifying the issue.

Inside ~/.local/lib:

user@user:~/.local/lib$ ls
python3.8  python3.9

Inside /usr/lib:

user@user:/usr/lib$ ls
Other packages
python2.7
python3
python3.11
python3.8
python3.9
Other packages

Inside the pipenv file of /usr/bin directory:

user@user:/usr/bin$ cat pipenv
#!/usr/bin/python3
# EASY-INSTALL-ENTRY-SCRIPT: 'pipenv==11.9.0','console_scripts','pipenv'
__requires__ = 'pipenv==11.9.0'
import re
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(
        load_entry_point('pipenv==11.9.0', 'console_scripts', 'pipenv')()
    )

Now as I'm trying to completely remote pipenv I tried uninstalling again:

user@user:~/Desktop/Test-ML$ pip uninstall pipenv
/usr/bin/pip:6: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  from pkg_resources import load_entry_point
Found existing installation: pipenv 11.9.0
Not uninstalling pipenv at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'pipenv'. No files were found to uninstall.

It failed. But if I check the version:

user@user:~/Desktop/Test-ML$ pipenv --version
/usr/bin/pipenv:6: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  from pkg_resources import load_entry_point
pipenv, version 11.9.0

I want to utilize the latest version of Pipenv to create and manage virtual environments while having the option to use the desired Python version.

Any guidance or suggestions would be greatly appreciated.

Thank you

Upvotes: 2

Views: 1631

Answers (1)

darth baba
darth baba

Reputation: 1398

I think python3.9 pip is still installed to uninstall try this

python3.9 -m pip uninstall pipenv

Then reinstall everything:

python3.11 -m pip install setuptools build wheel
python3.11 -m pip install pipenv

This should fix the problem to create and manage virtual environments tou can use pipenv --python 3.11

Upvotes: 1

Related Questions