How to make pip install stuff for another version of python - python

I had a working setup where I'd type pip install some-library and then I could import it into my projects. Then I decided to install miniconda which installed another version of python (3.8) that my system started defaulting to.
By running this command in terminal (I'm on a mac): alias python=/usr/local/bin/python3 I managed to revert so that when I type python [something], my system uses the python located there (not the newly created one).
It seems that it's not as straightforward to get pip to do the same though. pip install some-library just installs stuff for the wrong python version.
How can one make pip install some-library install some-library to the python version located in /usr/local/bin/python3?

You can try pip3 install some-library for python 3. I hope that works fine!

I think I figured it out.
In /usr/local/bin, I put an alias named "pip" that points to /Library/Frameworks/Python.framework/Versions/3.6/bin/pip3.6
Then i ran the following in terminal:
conda config --set auto_activate_base false
It seems conda kept resetting this whenever I opened terminal.
Inspiration from this thread: How do I prevent Conda from activating the base environment by default?

Related

ML and Django: using Conda and Pip depending on what I am doing... no? [duplicate]

conda 4.2.13
MacOSX 10.12.1
I am trying to install packages from pip to a fresh environment (virtual) created using anaconda. In the Anaconda docs it says this is perfectly fine. It is done the same way as for virtualenv.
Activate the environment where you want to put the program, then pip install a program...
I created an empty environment in Ananconda like this:
conda create -n shrink_venv
Activate it:
source activate shrink_venv
I then can see in the terminal that I am working in my env (shrink_venv). Problem is coming up, when I try to install a package using pip:
(shrink_venv): pip install Pillow
Requirement already satisfied (use --upgrade to upgrade): Pillow in /Library/Python/2.7/site-packages
So I can see it thinks the requirement is satisfied from the system-wide package. So it seems the environment is not working correctly, definitely not like it said in the docs. Am I doing something wrong here?
Just a note, I know you can use conda install for the packages, but I have had an issue with Pillow from anaconda, so I wanted to get it from pip, and since the docs say that is fine.
Output of which -a pip:
/usr/local/bin/pip
/Users/my_user/anaconda/bin/pip
** UPDATE **
I see this is pretty common issue. What I have found is that the conda env doesn't play well with the PYTHONPATH. The system seems to always look in the PYTHONPATH locations even when you're using a conda environment. Now, I always run unset PYTHONPATH when using a conda environment, and it works much better. I'm on a mac.
For others who run into this situation, I found this to be the most straightforward solution:
Run conda create -n venv_name and conda activate venv_name, where venv_name is the name of your virtual environment.
Run conda install pip. This will install pip to your venv directory.
Find your anaconda directory, and find the actual venv folder. It should be somewhere like /anaconda/envs/venv_name/.
Install new packages by doing /anaconda/envs/venv_name/bin/pip install package_name.
This should now successfully install packages using that virtual environment's pip!
All you have to do is open Anaconda Prompt and type
pip install package-name
It will automatically install to the anaconda environment without having to use
conda install package-name
Since some of the conda packages may lack support overtime it is required to install using pip and this is one way to do it
If you have pip installed in anaconda you can run the following in jupyter notebook or in your python shell that is linked to anaconda
pip.main(['install', 'package-name'])
Check your version of pip with pip.__version__. If it is version 10.x.x or above, then install your python package with this line of code
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--upgrade', 'package-name'])
In your jupyter notebook, you can install python packages through pip in a cell this way;
!pip install package-name
or you could use your python version associated with anaconda
!python3.6 -m pip install package-name
I solved this problem the following way:
If you have a non-conda pip as your default pip but conda python is your default python (as below)
>which -a pip
/home/<user>/.local/bin/pip
/home/<user>/.conda/envs/newenv/bin/pip
/usr/bin/pip
>which -a python
/home/<user>/.conda/envs/newenv/bin/python
/usr/bin/python
Then instead of just calling
pip install <package>, you can use the module flag -m with python so that it uses the anaconda python for the installation
python -m pip install <package>
This installs the package to the anaconda library directory rather than to the library directory associated with (the non-anaconda) pip
EDIT:
The reason this works is as follows:
the command pip references a specific pip file/shortcut (which -a pip tells you which one). Similarly, the command python references a specific python file (which -a python tells you which one). For one reason or another these two commands can become unsynchronized, so that your 'default' pip is in a different folder than your default python, and therefore is associated with a different version of python.
In contrast, the python -m pip construction does not use the shortcut that the pip command points to. Instead, it asks python to find its version of pip and use that version to install a package.
This is what worked for me (Refer to image linked)
Open Anaconda
Select Environments in the left hand pane below home
Just to the right of where you selected and below the "search environments" bar, you should see base(root). Click on it
A triangle pointing right should appear, click on it an select "open terminal"
Use the regular pip install command here. There is no need to point to an environment/ path
For future reference, you can find the folder your packages are downloading to if you happen to have a requirement already satisfied. You can see it if you scroll up in the terminal. It should read something like: requirement already satisfied and then the path
[]
If you didn't add pip when creating conda environment
conda create -n env_name pip
and also didn't install pip inside the environment
source activate env_name
conda install pip
then the only pip you got is the system pip, which will install packages globally.
Bus as you can see in this issue, even if you did either of the procedure mentioned above, the behavior of pip inside conda environment is still kind of undefined.
To ensure using the pip installed inside conda environment without having to type the lengthy /home/username/anaconda/envs/env_name/bin/pip, I wrote a shell function:
# Using pip to install packages inside conda environments.
cpip() {
ERROR_MSG="Not in a conda environment."
ERROR_MSG="$ERROR_MSG\nUse \`source activate ENV\`"
ERROR_MSG="$ERROR_MSG to enter a conda environment."
[ -z "$CONDA_DEFAULT_ENV" ] && echo "$ERROR_MSG" && return 1
ERROR_MSG='Pip not installed in current conda environment.'
ERROR_MSG="$ERROR_MSG\nUse \`conda install pip\`"
ERROR_MSG="$ERROR_MSG to install pip in current conda environment."
[ -e "$CONDA_PREFIX/bin/pip" ] || (echo "$ERROR_MSG" && return 2)
PIP="$CONDA_PREFIX/bin/pip"
"$PIP" "$#"
}
Hope this is helpful to you.
python -m pip install Pillow
Will use pip of current Python activated with
source activate shrink_venv
For those wishing to install a small number of packages in conda with pip then using,
sudo $(which pip) install <instert_package_name>
worked for me.
Explainaton
It seems, for me anyway, that which pip is very reliable for finding the conda env pip path to where you are. However, when using sudo, this seems to redirect paths or otherwise break this.
Using the $(which pip) executes this independently of the sudo or any of the commands and is akin to running /home/<username>/(mini)conda(3)/envs/<env_name>/pip in Linux. This is because $() is run separately and the text output added to the outer command.
All above answers are mainly based on use of virtualenv. I just have fresh installation of anaconda3 and don't have any virtualenv installed in it. So, I have found a better alternative to it without wondering about creating virtualenv.
If you have many pip and python version installed in linux, then first run below command to list all installed pip paths.
whereis pip
You will get something like this as output.
pip: /usr/bin/pip /home/prabhakar/anaconda3/bin/pip /usr/share/man/man1/pip.1.gz
Copy the path of pip which you want to use to install your package and paste it after sudo replacing /home/prabhakar/anaconda3/bin/pip in below command.
sudo /home/prabhakar/anaconda3/bin/pip install <package-name>
This worked pretty well for me. If you have any problem installing, please comment.
if you're using windows OS open Anaconda Prompt and type activate yourenvname
And if you're using mac or Linux OS open Terminal and type source activate yourenvname
yourenvname here is your desired environment in which you want to install pip package
after typing above command you must see that your environment name is changed from base to your typed environment yourenvname in console output (which means you're now in your desired environment context)
Then all you need to do is normal pip install command e.g pip install yourpackage
By doing so, the pip package will be installed in your Conda environment
I see a lot of good answers here but still wanted to share mine that worked for me especially if you are switching from pip-era to conda-era. By following this, you can install any packages using both conda and pip.
Background
PIP - Python package manager only
Conda - Both package and environment manager for many languages including Python
Install Pip by default every time you create a new conda environment
# this installs pip for your newly created environment
conda create -n my_new_env pip
# activate your new conda environment
conda activate my_new_env
# now you can install any packages using both conda and pip
conda install package_name
#or
pip install package_name
This gives you the flexibility to install any packages in conda environment even if they are not available in conda (e.g. wordcloud)
conda activate my_new_env
# will not work as wordcloud is not available in conda
conda install wordcloud
# works fine
pip install wordcloud
I was facing a problem in installing a non conda package on anaconda, I followed the most liked answer here and it didn't go well (maybe because my anaconda is in F directory and env created was in C and bin folder was not created, I have no idea but it didn't work).
According to anaconda pip is already installed ( which is found using the command "conda list" on anaconda prompt), but pip packages were not getting installed so here is what I did, I installed pip again and then pip installed the package.
conda install pip
pip install see
see is a non-conda package.
Depends on how did you configure your PATH environmental variable.
When your shell resolves the call to pip, which is the first bin it will find?
(test)$ whereis pip
pip: /home/borja/anaconda3/envs/test/bin/pip /home/borja/anaconda3/bin/pip
Make sure the bin folder from your anaconda installation is before /usr/lib (depending on how you did install pip). So an example:
(test) borja#xxxx:~$ pip install djangorestframework
....
Successfully installed asgiref-3.2.3 django-3.0.3 djangorestframework-3.11.0 pytz-2019.3 sqlparse-0.3.1
(test) borja#xxxx:~$ conda list | grep django
django 3.0.3 pypi_0 pypi
djangorestframework 3.11.0 pypi_0 pypi
We can see the djangorestframework was installed in my test environment but if I check my base:
(base) borja#xxxx:~$ conda list | grep django
It is empty.
Personally I like to handle all my PATH configuration using .pam_environment, here an example:
(base) borja#xxxx:~$ cat .pam_environment
PATH DEFAULT=/home/#{PAM_USER}/anaconda3/bin:${PATH}
One extra commet. The way how you install pip might create issues:
You should use: conda install pip --> new packages installed with pip will be added to conda list.
You shodul NOT use: sudo apt install python3-pip --> new packages will not be added to conda list (so are not managed by conda) but you will still be able to use them (chance of conflict).
Well I tried all the above methods. None worked for me because of an issue with the proxy settings within the corporate environment. Luckily I could open the pypi website from the browser. In the end, the following worked for me:
Activate your environment
Download the .whl package manually from
https://pypi.org/simple/<package_name>/
Navigate to the folder where you have downloaded the .whl from the command line with your environment activated
perform:
pip install package_name_whatever.whl
If you ONLY want to have a conda installation. Just remove all of the other python paths from your PATH variable.
Leaving only:
C:\ProgramData\Anaconda3
C:\ProgramData\Anaconda3\Scripts
C:\ProgramData\Anaconda3\Library\bin
This allows you to just use pip install * and it will install straight into your conda installation.
I know the original question was about conda under MacOS. But I would like to share the experience I've had on Ubuntu 20.04.
In my case, the issue was due to an alias defined in ~/.bashrc: alias pip='/usr/bin/pip3'. That alias was taking precedence on everything else.
So for testing purposes I've removed the alias running unalias pip command. Then the corresponding pip of the active conda environment has been executed properly.
The same issue was applicable to python command.
Given the information described in this Anaconda blog post, I think the best practice would be to create an environment file so that your conda environments can be created predictably.
I tried a few of the answers posted here without success and I didn't feel like messing around with python paths etc. Instead, I added an environment.yml file similar to this:
name: your-environment-name
channels:
- defaults
dependencies:
- python=3.9.12
- requests=2.28.1
- pandas=1.4.4
- pip=21.2.4
- pip:
- python-dotenv==0.19.2
This guarantees that you install all conda dependencies first, then install pip in the conda environment and use it to install dependencies that are unavailable through conda. This is predictable, reusable, and follows the advice described in the blog post.
You then create a new conda environment using the file with this command:
conda env create -f environment.yml
Uninstall the duplicated python installation. Just keep anaconda and create an env with the desired python version as specified here: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-python.html. Then your python and pip versions will change as you switch between envs.
I've looked at this answer and many other answers for hours today and couldn't figure this out with 30 years programming experience.
I ran:
conda create -n myenv python=3.9
conda activate myenv
and could not use pip. However, in another environment such as myenv2, myenv3, myenv4 it worked.
I was obtaining the dreaded urllib3 httpsconnection error.
So thought it has to be a missing urllib3 error or something else. It turns out that it was much more sinister than that. Unfortunately it works in other environments and for me I thought that it was related to the fact I'm using Debian on Windows 10 with WSL2. The fix was simple:
rm -rf $HOME/.cache
The pip cache was mangled from a previous install of the same environment. Probably due to the fact I had run an update on conda base and done a distribution upgrade. Because I'm wanting to run a production system with apache2 using a WSGI environment with flask, I want to always have the same conda instance name. So this was a must fix!

pip/python: normal site-packages is not writeable

I have a new Macbook - a user installed it, and then I installed a new user (mine), granted admin privileges and deleted the old one. I am on OS Catalina.
Since the installation I've been having several permission problems.
VSCode can't find Jupyter Notebook, pip installs packages at ~/Library/Python/3.7/site-packages.
When I do which python3 I get usr/bin/python3.
When I do pip3 install <package> I get: Defaulting to user installation because normal site-packages is not writeable And then it says it has already been installed, even though I can't access it when I do import <package>.
It's seems clear that this is a permission problem, pip can't install to the "base" python, and them python can't find what I've installed into ~/Library/Python/3.7/site-packages.
I've tried reinstalling the OS, but since I haven't done a clean install, it didn't change anything.
What am I missing?
How exactly can I fix permissions? Where do I want packages to be installed (venv sure, but some packages I want global (like jupyter).
As #TomdeGeus mentioned in the comments, this command works for me:
Python 3:
python3 -m pip install [package_name]
Python 2:
python -m pip install [package_name]
It's best to not use the system-provided Python directly. Leave that one alone since the OS can change it in undesired ways, as you experienced.
The best practice is to configure your own Python version(s) and manage them on a per-project basis using virtualenv (for Python 2) or venv, possibly via poetry, (for Python 3). This eliminates all dependency on the system-provided Python version, and also isolates each project from other projects on the machine.
Each project can have a different Python point version if needed, and gets its own site_packages directory so pip-installed libraries can also have different versions by project. This approach is a major problem-avoider.
python3.7 -m pip install [package_name]
(you should use the version that you have, of course)
solved it for me.
The most voted answer python3 -m pip install [package_name] does not help me here.
In my case, this was caused by a conflict with the dominating 3.6 version that was also installed as a default. You might ask yourself why you have 3.6 on your system, you will most probably not use that version now. The reason is that 3.6 is used as an independent default python version for many package installers. Those installers do not want to check which individual version you use and whether that fits, they just use 3.6 as a default, if you like it or not.
Here is a proof by example --upgrade pip:
pip3 install --upgrade pip
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pip in
/home/USERNAME/.local/lib/python3.6/site-packages (20.3.1)
python3 -m pip install --upgrade pip
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pip in
/home/USERNAME/.local/lib/python3.6/site-packages (20.3.1)
python3.7 -m pip install --upgrade pip
Collecting pip
Cache entry deserialization failed, entry ignored
Using cached https://files.pythonhosted.org/packages/ab/11/2dc62c5263d9eb322f2f028f7b56cd9d096bb8988fcf82d65fa2e4057afe/pip-20.3.1-py2.py3-none-any.whl
Installing collected packages: pip Successfully installed pip-20.3.1
I'm using Anaconda on Ubuntu and had the same problem.I fixed it by the following steps:
deactivating current environment
conda deactivate
Then, the base environment activates. I deactivated the base conda environment too. To do so, I used conda deactivate again.
Finally, I activate my project environment directly (instead of activating from the base environment) by the following command. Afterward, I installed the intended package successfully and worked perfectly.
conda activate myenv
pip install somepackage
sudo pip install
Worked for me. But pip install is not recommended to be run with sudo. The issue I was facing on BIGSUR was, it was using system python. Once I Installed python 3.9 using
brew install python#3.9
Then pip worked fine
For readers who thought themselves accidentally update system pip:
If you saw this info in your terminal output:
Defaulting to user installation because normal site-packages is not writeable
then you will be fine. Use the pip3 you just updated to run:
pyenv global system # since I use pyenv
pip3 uninstall pip # this one does the trick
Then you can check again pip3 --version will point to the original old (XCode/System-)pip. E.g. (2022/2/28):
pip 20.2.3 from /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)
It occurs with me when I the virtual enviroment folder name was : venv.
in this case, It gives errors like :
No module pip
Default folder is unwritable
renaming the folder solve the proplem.
Check on the command line "which python" to see if it is the value you expect.
If you have a virtual environment activated, check /venv/bin/activate to see the value of VIRTUAL_ENV= and make sure it is the correct path . The path may be wrong if you renamed or moved the project. If the path is wrong, you can delete the venv and make a new one.
For me, none of the suggestions worked so I had to delete the current virtual environment folder venv and recreate it using one of the following commands:
python -m venv venv
python3 -m venv venv
Check the source of pip on Ubuntu 20.04
which pip
returns the correct path
/home/myname/fullstack/person_api/venv/bin/pip
UPDATE
I presume that some might encounter this problem because they set python path as environmental variable like this in ~/.bashrc:
python=/path/to/python
which you should not be doing! Instead we could do:
py=python
PATH=/path/to/python:$PATH
I bumped into this issue specifically because of this!
Had this same issue on a fresh install of Debian 9.12.
Rebooting my server solved the issue.
In my case on Linux, the ownership of the conda env directory had changed to another Linux user (long story), and so the the normal site-packages was not writeable due to a permissions issue.
The solution was to change ownership back to the user doing pip install.
I met exactly the same issue.
I just type sudo python3.8 -m pip install .... and the error disappeared.
If I remove the sudo, issue remains.
For those running on a Pi, that accidentally installed pip as root. Just chown the lib folder to the pi user:
sudo chown -R pi:pi /usr/local/lib/python3.9/
in my case python3 -m pip install [package_name] did not solve that.
in my case, it was a problem related to other processes occupying the directory.
I restart Pycharm and close any other program that might occupy this folder, and reinstalled the package in site-packages directory successfully.
When this problem occurred to me I have tried all the mentioned approaches but they don't seem to work.
Instead, restarting Python language server in my VSCode did the job - my SimPy package is now found. On Mac it is Cmd+Shift+P and select "Python: Restart Language Server".
Had similar issue on Ubuntu 20.04.4 LTS in VirtualBox, but none of the suggestions here worked for me.
I was trying to install open3d in a venv and every time I was getting
"Defaulting to user installation because normal site-packages is not writeable"
which at first I didn't even noticed. open3d was always being installed in /usr/bin/python3 environment. I've restarted the VM but without luck, so I guess the problem was not just missing write access.
So in VS Code, which was using the venv, importing open3d was not possible. But testing from terminal from the activated venv with python3 -c "import open3d as o3d; print(o3d.__version__)" was working fine and that confused me totally. I even broke my system pip installation using sudo, see further below if you want to know how to fix it.
Anyhow, the solution to my problem was to explicitly point to the python3 file in the venv where I wanted to install the package:
venv/bin/python3 -m pip install open3d
So I was testing out everything and eventually installed with sudo: sudo pip3 install open3d. This of course didn't solved the problem and open3d was still missing in the venv. Even worse, I got the message:
"WARNING: You are using pip version 21.3.1; however, version 22.0.4 is available.
You should consider upgrading via the '/usr/bin/python3 -m pip install --upgrade pip' command."
So I did it but with sudo, updating the system pip and then found out here that this is not good:
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
Following an advice here, I tried to revert to original version, only then pip3 broke:
sudo pip3 uninstall pip
sudo pip3 --version
sudo: pip3: command not found
The apt package was still there:
sudo apt install python3-pip python3-pip is already the newest version
(20.0.2-5ubuntu1.6).
So I had to reinstalled to fix the problem:
sudo apt-get remove python3-pip
sudo apt install python3-pip
Maybe you have python, python3, pip or pip3 aliased. In that case pip might not work well anymore, as the alias isn't always available and so pip/pip3 might resolve python/python3 differently compared to in your terminal.
That could give rise to pip/pip3 trying to install in the system python, and that could give rise to your error.
I tried ever single recommendation described here. In every instance, I get the exact same result: SyntaxError: invalid syntax (<stdin>, line 1)
I'm not sure who designed the system like this, but it seems basically useless, based on my experience so far. Either create a system that works, or don't create anything at all.

How to install Python packages in a specific environment?

I installed Anaconda3 so I can create environments and install different packages in each environment. But I fail to understand the difference between the Python in
/usr/bin/python
and
/opt/anaconda3/bin/python
I can seem to access Python 3.6.5 Anaconda from both, why is that? And, what is the difference between both?
Furthermore, I would like to install packages to a single Python environment only.
When you are running python in the terminal, it is looking up your default path to your the python command. In this case, anaconda probably put a line in your shell profile specify the path to the anaconda version, which is why you are seeing it in the interpreter when you run python from either directory.
Secondly, you can set up a conda environment to download app specific dependencies without interfering with your default set up by
conda create --name myenv
source activate myenv
conda install packagename
This will install it in the myenv environment only. To deactivate the environment just run
source deactivate
Here is the documentation on that https://conda.io/docs/user-guide/tasks/manage-environments.html
Judging by your path, you are using Linux which comes with python installed. So /usr/bin/python is default and you have installed the other one later.
For the environments use https://conda.io/docs/user-guide/tasks/manage-environments.html to activate the desired environment, then you can pip install or conda install the packages and it will be places safely only in that environment. Note that spyder icon runs the root environment by default and you have to run it from terminal after activating one of the environments.
Edit:
I'm not sure why you want to use cd to change the python version. I suggest use aliases. I guess you are just changing the path but running the same version of the python anyway. Take a look at this question:
Two versions of python on linux. how to make 2.7 the default
I wanted to create a new virtual environment to install new packages. Following worked for me:
Commands are executed in Jupyter Notebook (OS: Ubuntu 16.04 LTS)
Upgrade pip:
!pip install --upgrade pip
Install virtual environment:
!pip install virtualenv
Select version of Python you want to use in new environment:
I wanted to create an environment with Python version 3. Naming it as Python3_xyz:
!virtualenv -p python3 Python3_xyz
After execution, this will create a folder with the same name in the current working directory (i.e. the location where Jupyter notebook is present)
Create a new option with the name of the created environment
And finally, run the following command:
!python -m ipykernel install --user --name=Python3_xyz
This will create a new option with the name Python3_xyz in the menu from where we create a new notebook.
NOTE: One can run above commands from the terminal as well just don't use '!' before the commands.
This question is bit dated, but since I faced a similar issue, what worked for me might help someone!
I did pip install requests from within my conda environment, but failed to import requests even after trying out everything.
What worked for me: run python -m pip install requests or python3 -m pip install requests within you environment. This installed requests successfully for me.

Windows reports error when trying to install package using pipenv

I installed pipenv by following the instructions here. From the Windows command prompt I ran
pip install --user pipenv
which returned the message
Successfully installed pipenv-5.3.3
Now I want to install the requests package using pipenv, so I ran
pipenv install requests
but this returned
'pipenv' is not recognized as an internal or external command,
operable program or batch file.
I have added the path
C:\Users\Robert\AppData\Roaming\Python\Python35\site-packages
to my Windows path environment variable, but I still receive the same error.
How can I install the requests package using pipenv?
EDIT: As I have remnants of Python 3.5 and Python 3.6 on my system, I'm going to uninstall everything and start anew. (I've just started learning Python and I want to keep this as simple as possible.)
I have a similar setup and faced a similar problem, but the solution I found was fairly simple. All of my PATH variables were already correct (from Python 3 the Windows Installer automatically does all of this).
The problem
The problem actually arises because of conflicting installations of virtualenv.
Fix
To address this problem you need to simply run the following commands:
First, remove your current version of virtualenv: pip uninstall virtualenv
Then, remove your current version of pipenv: pip uninstall pipenv
When you are asked Proceed (y/n)? just enter y. This will give you a clean slate.
Finally, you can once again install pipenv and its dependencies: pip install pipenv
This will also install the latest version of virtualenv.
Testing if it worked
Just enter pipenv --version in the command prompt and you should see the desired output.
Notes
I know this sounds the mundane, but it is actually the solution for Windows systems. You do not need to modify any of your system environment variables (please do not add site-packages to your environment variables).
python -m pipenv may work for you, (or python3 -m pipenv or py 3 -m pipenv) this is telling python to run the module pipenv instead of the terminal shortcut which sometimes doesn't install properly.
Just to show they are equivalent when I installed pipenv and run which pipenv it points to a file like /Library/Frameworks/Python.framework/Versions/3.6/bin/pipenv which looks like this:
#!/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
# -*- coding: utf-8 -*-
import re
import sys
from pipenv import cli
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(cli())
so it removes .pyw or .exe from the executable name then call pipenv.cli.cli(). It is likely there is a file like this on your machine it just didn't add python's /bin folder to your system PATH so it isn't accessible, there is usually a warning when installing python if this happens but no one checks those. :P
the module pipenv.__main__ which is run when using python -m pipenv looks like this:
from .cli import cli
if __name__ == '__main__':
cli()
Which calls pipenv.cli.cli(). So this main module absolutely does the same effective thing.
to solve this problem i need to start my CMD as administrator.
pip uninstall pipenv
pip install pipenv
To test this new configuration, you can write pipenv --version
Use python -m pipenv instead of just pipenv, it should work. Best of luck to you.
Try adding the following to Path environmental variable:
C:\Users\Robert\AppData\Roaming\Python\Python36\Scripts
instead of the \site-package, as that is where pipenv.exe is installed (at least for me).
use this cmd solve my problem :
python -m pipenv install django==2.1
Many thanks to #Srivats Shankar. In case you have tried what he said and it did not work, hope you did not forget to check your python path? If you have more than a single python version installed, doing pip uninstall virtualenv or pip uninstall pipenv might not help solve the problem.
Every python version is generally supposed to have its own pip installed. What you would do in this case is:
`-python -version_to_uninstall_virtualenv_from -m pip uninstall virtualenv; py --version -m pip uninstall virtualenv
-python -version_to_uninstall_pipenv_from -m pip uninstall pipenv; py --version -m pip uninstall pipenv`
Then you install pipenv with a similar command:
`-python -version_to_install_pipenv_on -m pip install pipenv; py --version -m pip uninstall pipenv`
I had an error like you sed and I just reinstalled pipenv and it fixed.
I used this command:
pip install pipenv
Instead of
C:\Users\Robert\AppData\Roaming\Python\Python35\site-packages
it should be
C:\Users\Robert\AppData\Roaming\Python\Python36\Scripts
after that, try closing and reopening the terminal
check warnings after installing pipenv. sometimes pipenv location not registered in environment variables.
I noticed several different situations with multiple python versions installed.
A preferred solution would be to use:
python -m pip install pipenv
This command for Python3.7 instance generates executables in
C:\Users\XXX\AppData\Local\Programs\Python\Python37\Scripts and it made setting up other packages easier.
Windows is not officially supported, I think.
ref: https://github.com/kennethreitz/pipenv/issues/70
Please check that pipenv is installed in your system by run following command in command promt:
pipenv --version
If it returns error, so please install again and set environment variable path in your system

Call correct pip in pyvenv environment python3.4

I installed a new pyvenv environment with the following commands:
python3.4 -m venv env
source env/bin/activate
However, when I call which pip, I get the following: /usr/bin/pip. Apparently, the system wide pip installation is still used. If I look at the pyvenv documentation, it states the following:
Changed in version 3.4: Installs pip by default, added the
--without-pip and --copies options
And this is correct, when trying to install pip in my activated environment, I get the following:
Requirement already up-to-date: pip in ./env/local/lib/python3.4/dist-packages
How do I make sure that when I call pip in my activated environment, pyvenv pip is called?
Looks like you (and I in my previous answer) were seeing the effects of a bug. Everything seems to be working in the newer versions of pyvenv-3.4.
$ pwd
~/test
$ pyvenv-3.4 myenv
$ source myenv/bin/activate
(myenv)$ which pip
~/test/myenv/bin/pip
I was having a similar issue, I asked my webhost (WebFaction) and got an excellent response. The Understanding pyvenv and pip in virtual environments with python 3.4 and above page is summarized below.
It seems that you don't have to worry about which pip your virtual environment is using. As long as your virtual environment is active, any packages will be installed in it, regardless of which pip is used.
One thing about Python 3.4 virtual environments is that if the package does not support Python's new "wheel" package format, the package will not install inside the virtual environment directory. It will still maintain a connection with the virtual environment however.
Because of this strangeness, I opted to just use virtualenv instead of pyvenv-3.4 and everything worked as expected.
The issue has been fixed on Ubuntu 14.10.
And if you installed python 3.4 by the following command on Centos6.
yum install http://dl.iuscommunity.org/pub/ius/stable/CentOS/6/x86_64/python34u-3.4.2-1.ius.centos6.x86_64.rpm
You should reopen a new terminal (or relogin your system).
It works for me. Good luck.

Categories