I’m going through the “Python Walkthrough Virtual Enviroments with Pipenv” video. I followed all the steps and they seemed to work until I tried pipenv --version to see if I could access it directly. It gives me the following error and I’m unsure what the solution is to this.
I looked at a post that talked about a similar issue but it was unclear how that person got to solve this problem. When I type in pip list, I see the pipenv but not when I type in conda list.
Any help/advice would be appreciated. Thank you so much!
I’ve looked into this thread, and this person had the same problem as me. However, he said it worked after he played around with it a little bit and it does not help that much. Tgrtim said that it is installed but not added to path and he suggested design5244640455 to edit .zshrc, but I can’t seem to understand what that is even though I’ve researched abt it. I’ve looked at stackoverflow and the web throughout the day and none of the solutions seems to work.
Is there a reason you need both pip and conda? (I don’t recall what happens in the video you mentioned above. This video is in the Python3 course, right?).
In order to access pip you have to add that to your PATH. PATH is an environment variable that tells your system where to look for executable files when you run a command in that shell.
What happens when you type: $ echo $PATH
You probably see something like /user/bin etc.
To edit the .zshrc file:
In your home dir.( or, if you’re not there yet type: cd) When you type ls -la in the terminal window, do you see a .zshrc file? If not, you have to add it. To create it:
Hello, thank you so much for the detailed response. I was playing around a bit after watching some tutorials online and for some reason when I type python3 -m pipenv it works but not if I just type pipenv.
It’s possible that you accidentally installed pipenv with a different version of Python, not the conda version. That would explain why it’s not showing up in conda list, but it’s hard to know for sure.
What happens when you run which python and which pip ?
If they both print the path to your Anaconda distribution, then there shouldn’t have been an issue.
It’s not entirely clear from that output either. In your first post the (base) prepending your prompt suggests that a conda envrionment is activated (this adds to your PATH). In the second example it seems like the environment is not activated.
Your outputs for which would be changed when that environment is activated (this would be not only a different install of Python but also a different set of python based site packages such as pip, pipenv and so on).
This both adds commands to your PATH that were not there (before the environment was activated) and leads conda based items to be chosen preferentially before other binaries.
As for what to actually do, if you are using conda then you’ll want to get that environment activated again- conda activate base should do it.
If however conda cannot be found then I think at some point your shell initialisation has changed so that conda is not running its normal set-up. This should probably be a few lines in .bashrc or .zshrc depending on whether you’re using bash or zsh that are normally added upon installing conda. If you’ve removed them then the following reply might be a useful read (you would need to adapt to the correct username and shell if using zsh and you can skip first para)
One other thing that I thought of (that I hope doesn’t add to any confusion) is that Python 3* might not be your default version. Python comes pre-installed on Macs, but it’s Python 2.7 (or whatever).
When you open a terminal window, type: python -v
if python 2.7 pops up, then you need to change your default version of Python (which I think might be the source of your issues here with installing things).
You will need to make Python 3.8 (or whatever version you have) to be your default.
Or, google, “how to make python3 the default on a mac using zsh?” and find a way to do it that suits you.
Python 2.7 is deprecated and not supported any longer. Most ppl have migrated their code over to 3.8. or should have by now. I doubt any company would be using legacy code…tho, I could be totally wrong.
That Python 2 is your system’s Python, so make sure you don’t try to get rid of it or your OS will break. Simply activating conda as @tgrtim suggested should make the current interpreter the Python version that you downloaded with Anaconda.
Run the following commands: conda activate which python which pip
if those all work, it should activate your conda base environment and show the python and pip that are included with Anaconda. Once you have determined that you are indeed using the Anaconda distribution of Python, run pip list again and see if your pipenv is in there. If it’s not there, you should be able to pip install it properly since the conda environment will be activated.
I typed in all 3 commands and they all work, and I can see the pipenv when I do pip list. Could you please explain why the “pip” command results in “zsh: command not found: pip” when I don’t type “conda activate” before? After I type “conda activate”, I can call pip with no errors but if I don’t type “conda activate” before, I can only type pip3.
Also, when I install bs4 or requests, am I supposed to do pip3 install bs4/requests or pip install bs4/requests? Thank you so much for the help!
When you activate the conda environment it will put itself at the head of your PATH. Conda has its own version of python and the envrionment would have its own “site-packages” (additional library/package downloads) such as pip, and, if you installed it, pipenv. By putting itself at the head of your PATH condas version of pip is chosen before any other on your system. So you are using a different pip package that cannot be found until conda adds itself to your PATH.
If you’re using conda I would highly suggest using conda’s own package repos instead of pip (if nothing else it is less prone to confusion). This would be conda install pipenv and so on instead of pip install. So install bs4/requests by first making sure a conda envrionment is avtivated then install using conda if at all possible, if it is not then use pip to install (which should be fine so long as the envrionment is activated).
Got it, thank you! When I try conda install pipenv, it gives me a package not found error:
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
PackagesNotFoundError: The following packages are not available from current channels:
I can see pipenv when I activate conda and type in pip list. However, when I try to download it with conda install, it doesn’t work. Will this be a problem in any way?
Also, conda install bs4/requests works perfectly:)
Ah no, it shouldn’t be a problem. It’s probably not available from the normal conda channels (it’d be conda-forge or something). If you need pipenv you can get it via pip anyway. I would however suggest avoiding mixing the conda environment with a pipenv environment as that seems like a recipe for disaster (at the very least use pipenv’s shell to avoid an abhorrent hodgepodge of environment variables). You can use the two together but it’s a little more complex- python - Pipenv with Conda? - Stack Overflow
I would highly suggest reading the following or something similar you know what you’re doing with virtual environments and why. Sadly codecademy do not explain it much and you get terrifying mashups with conda, pip and pipenv
The main point is to keep things cleaner and easier, sticking with a single tool to do this is a good place to start (by all means mix them up once you know what you’re doing if you want to).