最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - How do I install pip in my python3, but not miniconda? - Stack Overflow

programmeradmin3浏览0评论

I'm having issues installing pip in my python3. Also not sure if I'm setting up python and miniconda in the right location (If there is best practice, please advise). I believe I have install pip in my miniconda, but not my python3 (hence I can't import the packages in my python3.11 either). How would I fix this problem?

(base) jennykao@Haos-MacBook-Pro ~ % which python
python: aliased to /usr/local/bin/python3
(base) jennykao@Haos-MacBook-Pro ~ % pip -V
pip 25.0.1 from /Users/jennykao/miniconda3/lib/python3.12/site-packages/pip (python 3.12)
(base) jennykao@Haos-MacBook-Pro ~ % pip install numpy
Requirement already satisfied: numpy in ./miniconda3/lib/python3.12/site-packages (2.2.3)
(base) jennykao@Haos-MacBook-Pro ~ % python 
Python 3.11.1 (v3.11.1:a7a450f84a, Dec  6 2022, 15:24:06) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
>>> Í



I'm having issues installing pip in my python3. Also not sure if I'm setting up python and miniconda in the right location (If there is best practice, please advise). I believe I have install pip in my miniconda, but not my python3 (hence I can't import the packages in my python3.11 either). How would I fix this problem?

(base) jennykao@Haos-MacBook-Pro ~ % which python
python: aliased to /usr/local/bin/python3
(base) jennykao@Haos-MacBook-Pro ~ % pip -V
pip 25.0.1 from /Users/jennykao/miniconda3/lib/python3.12/site-packages/pip (python 3.12)
(base) jennykao@Haos-MacBook-Pro ~ % pip install numpy
Requirement already satisfied: numpy in ./miniconda3/lib/python3.12/site-packages (2.2.3)
(base) jennykao@Haos-MacBook-Pro ~ % python 
Python 3.11.1 (v3.11.1:a7a450f84a, Dec  6 2022, 15:24:06) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
>>> Í



Share Improve this question edited Feb 14 at 23:29 jenie asked Feb 14 at 22:40 jeniejenie 11 gold badge1 silver badge7 bronze badges 1
  • 1 Hi Jenie, going by the above, it looks like the python command on your terminal is resolving to a non-miniconda interpreter, if not the system python, maybe one you installed with brew or from the installer on python. . What are the outputs of ls -la /usr/local/bin/python3 in the terminal? and also, check /usr/local/bin/python3 -c 'import sys; print(sys.version, sys.executable) – juanpa.arrivillaga Commented Feb 15 at 4:32
Add a comment  | 

2 Answers 2

Reset to default 0

It seems you're trying use pip install <package_name> while in the python REPL, or into IDLE.

pip is meant to be used directly in the command line. Instead of starting the python application (by typing python into the command line before trying to pip install <package_name>, try pip install <package_name> directly into the command line.

If what you're trying to do is install separated instances of dependencies (i.e. a version of, say, numpy for use with a particular project while you run a different version of numpy for a different project and don't want the instances to collide) then the solution you're looking for is a virtual environment.

This answer gives you a detailed description of how to create, activate and deactivate a virtual environment. You can also find more information in the documentation here.

In order to control from which python pip is called, you should call pip like this python -m pip install numpy (or if you really want to be sure `/usr/local/bin/python3 -m pip install numpy). But, before installing the package, you should also create a virtual environment.

So the commands would be:

# Create the virtual environment in current directory
python -m venv venv
# Not sure if it works on mac.
source venv/bin/activate
# Install numpy in the virtual environment
python -m pip install numpy
发布评论

评论列表(0)

  1. 暂无评论