Use default Python while having Anaconda

Viewed 5582

For development in Python, I am using Miniconda on my Mac with macos Sierra. However, I have to use a framework that only works with the default Python (present at /usr/bin/python).

My question is: How can I install packages for this default Python? If I use pip some-package, this will automatically install the package for the root conda environment.

EDIT: As discussed in the comments, I agree it is a bad idea to mess with the system default version of Python. Instead, I would like this SDK to work in a conda environment or with Python 2.7 installed from python.org. However, none of these seem to work! How to get this working?

9 Answers

You are not trying to install any package, you are trying to install very specific package pynaoqi that require external SDK, that is compiled for the specific architecture. You should edit your question to reflect that.

According to what I saw on the Net, it is not a trivial task. First, make sure you have the version 2.5 of the SDK, that suits the MacOS version. Then, look at this script. As they say, in order to work the dynamic libraries should be renamed. By the way, you need 64-bit Python 2.7.

To install packages using the system Python you can use /usr/bin/easy_install, which ships with MacOS.

You may wish to install pip from there, by running:

sudo easy_install pip

Once you have pip installed, you won't be able to use it directly if the conda pip command is shadowing it. You have multiple options here, depending on your tastes. You may choose to alias the system pip to alias systempip=/usr/bin/pip, or have /usr/bin in front of /Users/user/anaconda/ in your $PATH.

As mentioned in other answers, messing with the system Python is not recommended, things may break, and you can (most) certainly get any package to work within a conda environment.

Some packages don't work out of the box with Anaconda's Python for some people because the distribution would default to a non-framework build of Python. A common complaint came from users of matplotlib, for example, who could not get figure windows to display properly. Fortunately, conda offers a framework build of python as well, named pythonw or pythonw3. Maybe you can try to get your package to work with pythonw, if that is where your problems come from.

Try this, find your way to path/to/python/scripts:

/usr/bin/python/scripts

And run pip here.

pip some-package is installing for the root anaconda environment because it is using pip from anaconda library. Anaconda add anaconda root dir to path before /usr/bin/ . so when you use pip if finds it on anaconda root. check path of pip using which pip, this will tell you complete path of pip.

You can install it on default python using /usr/bin/python -m pip install some-package. or use /path/to/default/pip install some-package.

The common issue is that anaconda (or miniconda) will have a python executable and pip executable in its bin directory.

If you truly need to run /usr/bin/python, this leads to the annoying conclusion: you cannot put conda in your path.

This lead me to some annoying machinations in my .bash_profile. You can use the same techniques for you, but your exact path to conda may differ:

# variables for using Conda
export BASE_PATH=$PATH
export CONDA_PATH="/Users/cmerriam/l/miniconda2/bin"
export CONDA_BIN="$CONDA_PATH/conda"
export CONDA_ACTIVATE="source $CONDA_PATH/activate"
export CONDA_DEACTIVATE="source $CONDA_PATH/deactivate"

# prompt function for [conda: myenv] when it is on.
function conda_branch {
  type $CONDA_BIN >/dev/null 2>&1 && $CONDA_BIN info --envs | grep \* | awk '{print $1;}' | grep -v '^root'
}
function conda_part {
  echo "[conda:$(conda_branch)]" | grep -v "\[conda:\]"
}


# Conda alias set
alias c="echo \"
   cls = list conda environments
   con <name> = activate conda environment
   coff = deactivate conda environment

   conda create -n tensorflow python=3.6 anaconda tensorflow jupyter
   conda remove --name tensorflow --all
   echo \\\$CONDA_DEFAULT_ENV\""
alias cls="$CONDA_BIN info --envs"
alias con="$CONDA_ACTIVATE"
alias coff="$CONDA_DEACTIVATE"

Option 2:

You may find you just need to run the same version or PYTHONPATH as /usr/bin/python. Then you make a conda environment with that version:

 conda create -n myenv python=2.7 

or, set a PYTHONPATH

 export PYTHONPATH=/usr/lib/python2.7/site-packages

Option 3:

Uninstall Conda. It is a good tool for a set of problems that is not your current set of problems.

I too have a Mac with Sierra.

Assumption: Let's say you have Anaconda. Now you would have DefaultPython(python2) and say this Anaconda is of Python3.

Secret: The way any shell/default python selected is with PATH variable set in a shell. So when you install Anaconda, installer shall try to set new path variables to your default bash shell

Solution: Have one python (2 or 3) as default. For the less used one, try using full path. If you have to use

Cheat code: create /usr/bin/python as symbolic link to the python's actual repo(save the old one). This can be altered according to your usage.

Hope this works!

I am not sure I correctly understood your problem, but if the problem is that you want to easily switch between several versions of python like system python, other versions of python, different versions of miniconda or anaconda bound to specific versions of python (that is not just virtual environments) on your mac, then the best solution is pyenv.

It automatically relinks where your current /usr/bin/python, /usr/bin/pip and other binaries like ipython currently look at depending on the context. There are several options of what context is, but I usually use system python as default and pyenv local for each project which basically puts a file with the version name in your current directory and each time you cd in the directory or its subdirecories /usr/bin/python is automatically switched to that version you selected.

You need to manage your PATH environment variable. I like to keep functions in my shell profile to turn conda "on" and "off." So, on a Mac for example:

deactconda() {
  export PATH="${PATH/\/Users\/<your_usrname>\/anaconda\/bin:/}" 
}

actconda() {
  export PATH=$HOME/anaconda/bin:$PATH
}

Then, whenever you want to stop using conda, just type deactconda at the prompt, etc.

You can do this multiple ways, first by providing the path to the pip in your default location,

your_default_python_path/pip install package

for example if you have a python 2.7 then,

sudo /usr/local/bin/pip2.7 install networkx

This should do the trick for you. After that you can install any packages and invoke them using default python(mine is 2.7 here)

with pip version 0.8 onwards you can also specify sudo /usr/local/bin/pip-2.x install package as well

Related