I'm attempting to use pipenv. I ran the command pip install pipenv, which ran successfully:
...
Successfully built pipenv pathlib shutilwhich pythonz-bd virtualenv-clone
Installing collected packages: virtualenv, pathlib, shutilwhich, backports.shutil-get-terminal-size, pythonz-bd, virtualenv-clone, pew, first, six, click, pip-tools, certifi, chardet, idna, urllib3, requests, pipenv
...
However, when I run the command pipenv install in a fresh root project directory I receive the following message: -bash: pipenv: command not found. I suspect that I might need to modify my .bashrc, but I'm unclear about what to add to the file or if modification is even necessary.
This fixed it for me:
sudo -H pip install -U pipenv
That happens because you are not installing it globally (system wide). For it to be available in your path you need to install it using sudo, like this:
$ sudo pip install pipenv
If you've done a user installation, you'll need to add the right folder to your PATH variable.
PYTHON_BIN_PATH="$(python3 -m site --user-base)/bin"
PATH="$PATH:$PYTHON_BIN_PATH"
See pipenv's installation instructions
I tried this:
python -m pipenv # for python2
python3 -m pipenv # for python3
Why this works: In Bash and other Unix-like shell environments, the -m option is used to specify a module to be run as a script.
When you run a Python script using the python -m command, you are telling the Python interpreter to execute the script as if it were a top-level module, rather than as a script file. The python -m pipenv command tells the Python interpreter to run the pipenv module as a script. The pipenv module must be importable from the current working directory or from one of the directories in the PYTHONPATH environment variable.
I have same problem with pipenv on Mac OS X 10.13 High Seirra, another Mac works just fine. I use Heroku to deploy my Django servers, some in 2.7 and some in 3.6. So, I need both 2.7 and 3.6. When HomeBrew install Python, it keeps python points to original 2.7, and python3 points to 3.6.
The problem might due to $ pip install pipenv. I checked /usr/local/bin and pipenv isn't there. So, I tried a full uninstall:
$ pip uninstall pipenv
Cannot uninstall requirement pipenv, not installed
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
$ pip3 uninstall pipenv
Skipping pipenv as it is not installed.
Then reinstall and works now:
$ pip3 install pipenv
Collecting pipenv
Where Python store packages
Before jumping into the command that will install pipenv, it is worth understanding where pip installs Python packages.
Global site-packages is where Python installs packages that will be available to all users and all Python applications on the system. You can check the global site package with the command
python -m site
For example, on Linux with Python 3.7 the path is usually
/usr/lib/python3.7/dist-packages/setuptools
User site-packages is where Python installs packages available only for you. But the packages will still be visible to all Python projects that you create. You can get the path with
python -m site --user-base
On Linux with Python 3.7 the path is usually
~/.local/lib/python3.7/site-packages
Using Python 3.x
On most Linux and other Unices, usually Python 2 and Python 3 is installed side-by-side. The default Python 3 executable is almost always python3. pip may be available as either of the following, depending on your Linux distribution
pip3
python3-pip
python36-pip
python3.6-pip
Linux
Avoid using pip with sudo! Yes, it's the most convenient way to install Python packages and the executable is available at /usr/local/bin/pipenv, but it also mean that specific package is always visible for all users, and all Python projects that you create. Instead, use per-user site packages instead with --user
pip3 install --user pipenv
pipenv is available at
~/.local/bin/pipenv
macOS
On macOS, Homebrew is the recommended way to install Python. You can easily upgrade Python, install multiple versions of Python and switch between versions using Homebrew.
If you are using Homebrew'ed Python, pip install --user is disabled. The global site-package is located at
/usr/local/lib/python3.y/site-packages
and you can safely install Python packages here. Python 3.y also searches for modules in:
/Library/Python/3.y/site-packages
~/Library/Python/3.y/lib/python/site-packages
Windows
For legacy reasons, Python is installed in C:\Python37. The Python executable is usually named py.exe, and you can run pip with py -m pip.
Global site packages is installed in
C:\Python37\lib\site-packages
Since you don't usually share your Windows devices, it is also OK to install a package globally
py -m pip install pipenv
pipenv is now available at
C:\Python37\Scripts\pipenv.exe
I don't recommend install Python packages in Windows with --user, because the default user site-package directory is in your Windows roaming profile
C:\Users\user\AppData\Roaming\Python\Python37\site-packages
The roaming profile is used in Terminal Services (Remote Desktop, Citrix, etc) and when you log on / off in a corporate environment. Slow login, logoff and reboot in Windows can be caused by a large roaming profile.
OSX GUYS, OVER HERE!!!
As #charlax answered (for me the best one), you can use a more dynamic command to set PATH, buuut for mac users this could not work, sometimes your USER_BASE path got from site is wrong, so you need to find out where your python installation is.
$ which python3
/usr/local/bin/python3.6
you'll get a symlink, then you need to find the source's symlink.
$ ls -la /usr/local/bin/python3.6
lrwxr-xr-x 1 root wheel 71 Mar 14 17:56 /usr/local/bin/python3.6 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
(this ../../../ means root)
So you found the python path (/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6), then you just need to put in you ~/.bashrc as follows:
export PATH="$PATH:/Library/Frameworks/Python.framework/Versions/3.6/bin"
Installing pipenv globally can have an adverse effect by overwriting the global/system-managed pip installation, thus resulting in import errors when trying to run pip.
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 to restore the system managed environment:
sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall
^ found here: Error after upgrading pip: cannot import name 'main'
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 effect (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
I don't know what happened, but the following did the work (under mac os catalina)
$ brew install pipenv
$ brew update pipenv
after doing this i am able to use
$ pipenv install [package_name]
OS : Linux
Pip version : pip3
sudo -H pip3 install -U pipenv
OS : Windows
Pip version : any one
sudo -H pip install -U pipenv
For thse who installed it using sudo pip3 install pipenv, you need to use python3 -m pipenv shell or python3.9 -m pipenv shell
I'm using zsh on my Mac, what worked for me is at first install pipenv
pip3 install --user pipenv
Then I changed the PATH in the ~/.zshrc
vi ~/.zshrc
In the editor press i to insert your text:
export PATH="/Users/yourUser/Library/Python/3.9/bin:$PATH"
Press esc and then write :wq!
Close the terminal and re-open it.
And finally write pipenv
This way worked for me using macOS BigSur 11.1
On Mac you may have to do:
pip3 install pipenv
Then, cd into your root directory to locate the .zshrc file.
Then add this to path
export PATH=/Library/Frameworks/Python.framework/Versions/3.9/bin:$PATH
Note: 3.9 is the version of Python running on your system.
Note: You can access the .zshrc by using cmd + shift + .
in your root directory... the file is hidden by default
Save and restart your terminal
Fixed this easily by installing pipenv with my central package manager (apt)
sudo apt install pipenv
You could easily install pipenv using your package manager (apt, yum, brew) and it adds it directly to your $PATH variables.
More to mention is it works on zsh. I use zsh on Ubuntu and tried adding pipenv to $PATH and other solutions but didn't work till I used apt to install it.
HOW TO MAKE PIPENV A BASIC COMMAND
Pipenv with Python3 needs to be run as "$ python -m pipenv [command]" or "$ python3 -m pipenv [command]"; the "python" command at the beginning varies based on how you activate Python in your shell. To fix and set to "$ pipenv [command]": [example in Git Bash]
$ cd ~
$ code .bash_profile
The first line is necessary as it allows you to access the .bash_profile file. The second line opens .bash_profile in VSCode, so insert your default code editor's command.
At this point you'll want to (in .bash_profile) edit the file, adding this line of code:
alias pipenv='python -m pipenv'
Then save the file and into Git Bash, enter:
$ source .bash_profile
You can then use pipenv as a command anywhere, for example:
$ pipenv shell
Will work.
This method of usage will work for creating commands in Git Bash. For example:
alias python='winpty python.exe'
entered into the .bash_profile and:
$ source .bash_profile
will allow Python to be run as "python".
You're welcome.
On Mac OS X Catalina it appears to follow the Linux path. Using any of:
pip install pipenv
pip3 install pipenv
sudo pip install pipenv
sudo pip3 install pipenv
Essentially installs pipenv here:
/Users/mike/Library/Python/3.7/lib/python/site-packages/pipenv
But its not the executable and so is never found. The only thing that worked for me was
pip install --user pipenv
This seems to result in an __init__.py file in the above directory that has contents to correctly expose the pipenv command.
and everything started working, when all other posted and commented suggestions on this question failed.
The pipenv package certainly seems quite picky.
If you are on MAC
sudo -H pip3 install pipenv
For window users this may be due to conflicting installation with virtualenv. For me it worked when I uninstalled virtualenv and pipenv first, and then install only pipenv.
pip uninstall virtualenv
pip uninstall pipenv
pip install pipenv
Now pipenv install xxx worked for me
After installing pipenv (sudo pip install pipenv), I kept getting the "Command Not Found" error when attempting to run the pipenv shell command.
I finally fixed it with the following code:
pip3 install pipenv
pipenv shell
Here is how I successfully resolved "Pipenv: Command Not Found" on my Mac OSX
You should change the ownership of these directories to your user.
sudo chown -R $(whoami) /usr/local/share
make sure that your user has write permission.
chmod u+w /usr/local/share
Then Consider installing with Homebrew:
brew update
brew install pyenv
This simply solved it for me if you are on windows.
pip install pipenv
Second, replace your <username> in the following paths and add them to the PATH environment variable:
c:\Users\<username>\AppData\Roaming\Python\Python38\Site-Packages
C:\Users\<username>\AppData\Roaming\Python\Python38\Scripts
You need to close the Command Prompt and reopen it.
Third, type the following command to check if the pipenv installed correctly:
pipenv -h
I hope this helps you too!
In this case you just need to add the binary path to your bash. In case you're using ZSH for example you need to edit the.zshrc file as an admind and then add the code mentioned by #charlax on the comments above:
PYTHON_BIN_PATH="$(python3 -m site --user-base)/bin"
PATH="$PATH:$PYTHON_BIN_PATH"
You might consider installing pipenv via pipsi.
curl https://raw.githubusercontent.com/mitsuhiko/pipsi/master/get -pipsi.py | python3
pipsi install pew
pipsi install pipenv
Unfortunately there are some issues with macOS + python3 at the time of writing, see 1, 2. In my case I had to change the bashprompt to #!/Users/einselbst/.local/venvs/pipsi/bin/python
In some cases of old pip version:
sudo easy_install pip
sudo pip install pipenv
First check if pipenv is installed:
pipenv --version
If no version is available on your system, then run the following command to install pipenv
sudo aptitude install pipenv
first install pip using following command
pip3 install pipenv
Now check whether pipenv is showing by using following command
pipenv --version if you see like command not found: pipenv use following commands
Now we have to set the path for pipenv, to do that first we have to find the user base binary directory,
On linux and Mac we can do it as following
python3 -m site --user-base
this command will display something like this
/some_directory/Python/3.9
use the path displayed in your terminal and append /bin at the end, now your path looks like this
/some_directory/Python/3.9/bin
now you have to set the path, if you are using zsh (z shell) type nano ~/.zshrc in the terminal or if you are using code editor like VSCode and path is set for VScode type code ~/.zshrc
if you are using bash use nano ~/.bashrc or code ~/.bashrc
in the file at last add following line
export PATH="$PATH:/somedirectory/Python/3.9/bin"
save the file and exit the terminal
now open new terminal and type pipenv --version you should see something like pipenv, version 2022.10.25
on Windows we can do as following
python -m site --user-site
you should see something like
C:\Users\Username\AppData\Roaming\Python36\site-packages`
now replace site-packages with Scripts.
this could return
C:\Users\Username\AppData\Roaming\Python36\Scripts
You can set your user PATH permanently in the Control Panel. You may need to log out for the PATH changes to take effect.
It's probably installed in your user path.
for instance, if your user(username) is tom check this path
/home/tom/.local/bin/pipenv
if pipenv exists in the path you can move or copy it to the general user path, so you can execute pipenv from all terminal sessions.
cp /home/tom/.local/bin/pipenv /usr/bin/
then you should be able to run pipenv
For me, what worked on Windows was running Command Prompt as administrator and then installing pipenv globally: python -m pip install pipenv.
After I installed Python and Djangom, I'm trying to use virtualenv for django project purpose using virtualenv. I installed virtualenv using pip.
pip install virtualenv # got install successfully
When I tried to run it, I got the error message
C:\Users\gshiv\Desktop\DjangoProject>virtualenv
'virtualenv' is not recognized as an internal or external command,
operable program or batch file.
steps:
- go to where you want create django app on that folder.
then run this command on command prompt : python -m virtualenv .
(eg. C:\Users\gshiv\Desktop\django>python -m virtualenv .)
where django is the my folder i want run virtualenv and .(dot) indicates virtualenv install all it's folder in django folder otherwise you can use other folder name instead .(dot) this time virtulenv creates a folder in main folder(django) .
after running this command: run .\scripts\activate now you can see this type of line on cmd-prompt (django) C:\Users\gshiv\Desktop\django>
i.e main folder name before the source path. now you can install any modules for your project that belongs to that main folder only.
pip install django works fine.
If you can not find your virtualenv command in the windows console/terminal after installing it with pip, try this to make your environment 🔽
python -m virtualenv <nameOfEnv>
If you want to use a specific version of python, initialize it like this 🔽
python -m virtualenv <nameOfEnv> -p=<C:/path/to/python/version3.x.x/python.exe>
When using windows for first installation, you can use python from WindowsApp
Run pip uninstall virtualenv and then pip install virtualenv
There are three points that you need to consider:
Make sure that in the windows PATH variable there is an entry with your python installation and the scripts subfolder eg: C:\Program Files (x86)\Python36-32\ and C:\Program Files (x86)\Python36-32\Scripts\
When using pip install virtualenv, make sure that you run cmd as administrator. Otherwise, there might an access denied error during installation and virtualenv will not be installed properly.
Make sure that virtualenv has been installed correctly. Check in the python scripts subfolder - there must exist an .exe named virtualenv.exe. If not, uninstall will pip uninstall virtualenv and install again.
When I ran the pip install virtualenv command I got:
Requirement already satisfied: virtualenv in c:\directory\to\appdata\roaming\python\python36\site-packages
so I tried forcing upgrade:
pip install --upgrade --force virtualenv
py -3 -m venv venv
try using the above command.
virtualenv venv
will work on only older version of python
Use
python -m venv abc
Where abc is the name of the virtual environment
Run CMD as administrator and then enter
pip uninstall virtualenv
then re-run CMD as administrator and run
pip install virtualenv
Step 1: Run pip uninstall virtualenv.
Step 2: Run pip install virtualenv.
Step 2.1: Run virtualenv to check if it's now working...
Step 3: Still not working? Go to your prevouis console log to find where it says "WARNING: The script virtualenv.exe is installed in
'C:\Users\username\AppData\Roaming\Python\Python310\Scripts' which
is not on PATH."
Step 4: Copy the specified path from the warning message.
Step 5: Search for and open "System Properties" on your PC.
Step 6: Click the Advance tab, and then the Environment Variables Button on the bottom right.
Step 7: Click the variable value "Path" and then click edit.
Step 8: In the Edit Environment variable window, click new then paste your path in any slot.
Step 9: MAKE SURE you click OK twice and not to just exit out.
Step 10: Reboot terminal and check again.
Use py -m virtualenv Your_Folder_Name
To install to a specific folder e.g E:\publish
pip install virtualenv
virtualenv .
Try to run
PowerShell.exe -command "./venv/Scripts/activate"
You just need to reinstall virtualenv. First of all you need to uninstall virtualenv with this command.
pip uninstall virtualenv
Then just reinstall with this command.
pip install virtualenv
Solution-1: python -m venv name_of_virtual_environment
E:\code\python\tvenv>python -m venv myenv
E:\code\python\tvenv>cd myenv\Scripts\
E:\code\python\tvenv\myenv\Scripts>activate.bat
(myenv) E:\code\python\tvenv\myenv\Scripts>deactivate.bat
E:\code\python\tvenv\myenv\Scripts>
Solution-2: py -3 -m venv name_of_virtual_environment
E:\code\python\tvenv>py -3 -m venv myenv
E:\code\python\tvenv>cd myenv\Scripts
E:\code\python\tvenv\myenv\Scripts>activate.bat
(myenv) E:\code\python\tvenv\myenv\Scripts>deactivate.bat
E:\code\python\tvenv\myenv\Scripts>
For windows
First, install -> pip install virtualenvwrapper-win
Then setup -> mkvirtualenv myproject
Then you see the list of virtual environment
To see it you write-> lsvirtualenv
For working this environment we write -> workon myproject
I had this same issue using python3.
The solution was to use the python3 -m virtualenv . command.
This almost works for all
Open Command Prompt, navigate it to the Envs folder, run "env_name\Scripts\activate"
Check whether virtualenv is installed or not, if not install it:
pip install virtualenv
pip install virtualenvwrapper-win
Game On. Check on your IDE.
Try executing virtualenv.exe from its absolute path, like in my case i found it in C:\Users\<your user>\AppData\Roaming\Python\Python37\Scripts\virtualenv.exe.
I tried this and it worked, here refer the logs as follows:
Using base prefix c:\\users\\<user>\\appdata\\local\\programs\\python\\python37-32
New python executable in C:\somedir\dir2\dir3\ML_1\ml\env\Scripts\python.exe
Installing setuptools, pip, wheel...
done.
I got this error too but I figure it out.
you just have to open PowerShell as administrator and then write following command Set-ExecutionPolicy unrestricted then type A. you are all set!
now uninstall the packages and re-install them.
Now if you write flask --version or virtualenv --version There will be no error at all.
Windows
If you want to use the lsvirtualenv command with virtualenv, follow the steps below.
Incorrect:
python -m pip install virtualenv
python -m pip install virtualenvwrapper
Correct:
python -m pip install virtualenv
python -m pip install virtualenvwrapper-win
Basic Uses
Then, to create a virtual environment:
mkvirtualenv youVirtualEnvironmentName
It will be activated automatically:
C:\Users\YourUserName (youVirtualEnvironmentName) λ
First, to access an existing virtual environment:
C:\Users\YourUserName λ workon youVirtualEnvironmentName
Next, to exit the currently active virtual environment:
C:\Users\YourUserName (youVirtualEnvironmentName) λ deactivate
Finally, to list all your virtual environments:
C:\Users\YourUserName λ lsvirtualenv
dir /b /ad 'C:\Users\YourUserName\Envs'
==================================================================
youVirtualEnvironmentName
Make sure that virtualenv has been installed correctly. Check in the python scripts subfolder - there must exist an .exe named virtualenv.exe. If not, uninstall will pip uninstall virtualenv and install again.
1)First Way as
python -m virtualenv name_of_virtual_environment
OR
2)Second Way as
py -3 -m venv name_of_virtual_environment
Open a cmd or ps with run as admin.
Now run pip uninstall virtual.
pip install virtual.
Done :D
Implementation:
Go to the directory where you want to make a python env.
type: virtualenv myEnv
beep bop boop done.
ps: Always use cmd or powershell with run as admin if you're installing some new package.