1

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!

jr15
  • 415
  • 6
  • 9
  • you seem to have multiple pythons. What is your system? How about removing homebrew's python and installing conda? Conda uses environments to run different versions of python if you need them, https://www.anaconda.com/distribution/ – Dima Lituiev Feb 04 '19 at 00:18
  • I'm using macOS (Mojave), I forgot to add that. What do environments do to solve my problem? – jr15 Feb 04 '19 at 00:27

1 Answers1

2

System Python

You can check the absolute paths and versions of python and pip to get a clear overview:

$ 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

Then you can check the versions with:

$ /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)

You can list the installed packages with:

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

Conda

Nevertheless I recommend you to check Anaconda or, even better, miniconda (see the differences). It helps you to install and manage different environments with different Python and package versions. After the installation you do usually:

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

Paths:

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

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

Versions:

$ python --version
Python 3.7.2

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

Installed packages:

$ 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

Or the whole conda environment 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
Darius
  • 10,762
  • 2
  • 29
  • 50
  • Could you elaborate a little on what Conda does, what environments are, and how to use them? I'm not finding the Anaconda website very revealing in that regard. I'm sorry, I can tell that these are almost trivial questions but I just don't have the knowledge base to contextualize them – jr15 Feb 04 '19 at 00:39
  • 1
    There are some good explanation videos on YouTube, e.g. [Python Tutorial: Anaconda - Installation and Using Conda](https://www.youtube.com/watch?v=YJC6ldI3hWk). – Darius Feb 04 '19 at 01:01
  • Almost two years later I want to thank you, Conda has been a godsend – jr15 Dec 03 '20 at 22:19