Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

installation of pipenv causes pip3 unusable

I installed pipenv using
$ pip3 install pipenv
which gives me the error ImportError: cannot import name 'main'
in order to solve this error I followed these instruction
sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall
now pip3 command is working on terminal.
now I install pipenv using pip3 install pipenv
it installed succesfully but when i tried to execute pipenv on termnal it gave me pipenv: command not found
at this point pip3 also gives ImportError: cannot import name 'main' error
in order to solve this i followed these instruction

PYTHON_BIN_PATH="$(python3 -m site --user-base)/bin"
PATH="$PATH:$PYTHON_BIN_PATH"

at this, point pipenv is working but pip3 is not working .
How can I make both pip3 and pipenv work at the same time?

Also, it seems that I have messed up my pipenv setting now the virtual environment is created by default at /home/sysadmin instead of the location i used to create virtual environment /home/sysadmin/Desktop/helloworld

enter image description here

like image 222
Vishal Singh Avatar asked Oct 29 '22 09:10

Vishal Singh


1 Answers

The problem is due to overwriting the system-managed version of pip when installing pipenv. You performed the correct first step by getting your system-managed pip back in order:

sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall

Once that is done, it is important to note that pipenv will likely not be able to be installed at the global level due to the pip conflict. You can install pipenv at the user level:

pip install --user pipenv

This should install pipenv at a user-level in /home/username/.local so that it does not conflict with the global version of pip. In my case, that still did not work after running the '--user' switch, so I ran the longer 'fix what I screwed up' command once more to prep the environment:

sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall

and then did the following:

mkdir /home/username/.local ... if it doesn't already exist

export PYTHONUSERBASE=/home/username/.local

Make sure the export took (bit me once during this process):

echo $PYTHONUSERBASE

Then, I ran the pip install --user pipenv and all was well. I could then run pipenv from the CLI and it did not overwrite the global/system-managed pip module. Of course, this is specific to the user so you want to make sure you install pipenv this way while working as the user you wish to use pipenv.

References:

https://pipenv.readthedocs.io/en/latest/diagnose/#no-module-named-module-name https://pipenv.readthedocs.io/en/latest/install/#pragmatic-installation-of-pipenv https://pip.pypa.io/en/stable/user_guide/#user-installs

like image 115
NetRay Avatar answered Nov 14 '22 22:11

NetRay