首页 > 解决方案 > Multiple Locations for Python Packages

问题描述

I'm fairly new to computing, and am having trouble sorting through various Python package installation locations (EDIT: on macOS Mojave). I seem to have various python packages in the following:

/Library/Python: I have 2.6, 2.7, and 3.6 here. 2.7 has packages that I've downloaded, the other two are mostly empty

/usr/local: in Homebrew's Cellar/python I have a 3.7, and in /lib I have lots of Python 3.7 packages

/Users/user/Library/Python: 2.7 with lots of packages, 3.7 with other packages that I don't think I downloaded (astroid, plylint, six, wrapt)

My issue is that I install things with pip3, and often regular pip as well as backup, but when I try to use the packages I've downloaded for python3 it doesn't seem to be able to find them. I hope it's readily apparent I don't know much. I've tried finding answers elsewhere but can't seem to. Any help is appreciated!

标签: pythonpython-3.xpython-2.7

解决方案


系统 Python

您可以检查 python 和 pip 的绝对路径和版本以获得清晰的概述:

$ which -a python
/opt/miniconda/bin/python
/usr/local/bin/python
/usr/bin/python

$ which -a pip
/opt/miniconda/bin/pip
/usr/local/bin/pip

然后您可以使用以下命令检查版本:

$ /usr/bin/python --version
Python 2.7.10

$ /usr/local/bin/pip --version
pip 18.1 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)

您可以列出已安装的软件包:

$ /usr/local/bin/pip freeze
protobuf==3.6.1
pycairo==1.18.0
six==1.11.0

康达

不过,我建议您检查Anaconda,或者更好的是miniconda(请参阅差异)。它可以帮助您使用不同的 Python 和包版本安装和管理不同的环境。安装后您通常会执行以下操作:

$ conda create -n env_name python=3.7 -y
$ source activate env_name
$ conda install scikit-learn pandas

路径:

$ which python
/opt/miniconda/envs/env_name/bin/python

$ which pip
/opt/miniconda/envs/env_name/bin/pip

版本:

$ python --version
Python 3.7.2

$ pip --version
pip 18.1 from /opt/miniconda/envs/env_name/lib/python3.7/site-packages/pip 

已安装的软件包:

$ pip freeze
certifi==2018.11.29
mkl-fft==1.0.10
mkl-random==1.0.2
numpy==1.15.4
pandas==0.24.0
python-dateutil==2.7.5
pytz==2018.9
scikit-learn==0.20.2
scipy==1.2.0
six==1.12.0

或整个 conda 环境env_name

$ conda env export
name: env_name
channels:
  - defaults
dependencies:
  - blas=1.0=mkl
  - ca-certificates=2018.12.5=0
  - certifi=2018.11.29=py37_0
  - intel-openmp=2019.1=144
  - libcxx=4.0.1=hcfea43d_1
  - libcxxabi=4.0.1=hcfea43d_1
  - libedit=3.1.20181209=hb402a30_0
  - libffi=3.2.1=h475c297_4
  - libgfortran=3.0.1=h93005f0_2
  - mkl=2019.1=144
  - mkl_fft=1.0.10=py37h5e564d8_0
  - mkl_random=1.0.2=py37h27c97d8_0
  - ncurses=6.1=h0a44026_1
  - numpy=1.15.4=py37hacdab7b_0
  - numpy-base=1.15.4=py37h6575580_0
  - openssl=1.1.1a=h1de35cc_0
  - pandas=0.24.0=py37h0a44026_0
  - pip=18.1=py37_0
  - python=3.7.2=haf84260_0
  - python-dateutil=2.7.5=py37_0
  - pytz=2018.9=py37_0
  - readline=7.0=h1de35cc_5
  - scikit-learn=0.20.2=py37h27c97d8_0
  - scipy=1.2.0=py37h1410ff5_0
  - setuptools=40.6.3=py37_0
  - six=1.12.0=py37_0
  - sqlite=3.26.0=ha441bb4_0
  - tk=8.6.8=ha441bb4_0
  - wheel=0.32.3=py37_0
  - xz=5.2.4=h1de35cc_4
  - zlib=1.2.11=h1de35cc_3
prefix: /opt/miniconda/envs/env_name

推荐阅读