I have read elsewhere that brew is a better option than pip to install packages (and indeed I had less problems installing Python packages with brew than with pip). The problem is that when I run
brew update && brew outdated && brew upgrade --all
and then
pip-review -a
it seems like the same packages are installed twice (for example matplotlib, scipy, and the like).
How can I get rid of pip and switch entirely to brew, as to avoid double installations and potential conflicts?
You can't do that. You cannot expect all python packages available via brew.
pip is the python package manager, having an understanding of how the python packages should be installed by querying a remote server of python packages called PyPI.
Brew, on the other hand, is a general software installation system for your Mac. It is a project into existence only because Apple is lazy to provide a good package manager and package management system for installing Unix/ Mac software on Apple.
There are many Python packages which exist on brew as volunteers took the pain to convert it to brew formulae. But it certainly does not guarantee of 100% 1-1 mapping of brew package to pip installable package.
You still want to use pip, you just should be using Homebrew's copy of it, rather than some other variant. Homebrew's copy of pip is part of the python package, so if you brew install python you'll have pip all setup and ready to go.
To clean up any non-Homebrew-provided pip packages, just delete the folder the module is in directly. For example, if you manually installed pip, the modules are probably stored under /Library/Python/2.7/site-packages somewhere.
Related
So im pretty new to python and i need pip for something i wanna do, but everytime i install python the Scripts folder where pip should be always installs empty. I make sure that install pip is checked when downloading python. How do I get it to install pip with python?
If you installed Python, it came bundled with pip.
The default packages:
C:\Users\<Your username>\AppData\Local\Programs\Python\Python310\Lib\site-packages
A better practice is to install a venv for every project you are working on. Every venv will have its own set of dependencies(i.e. packages), and it will be easier to manage them.
You can find installed packages in your venv:
YOUR_PROJECT_PATH\venv\Lib\site-packages
EDIT
From official docs:
Pip not installed¶ It is possible that pip does not get installed by default. One potential fix is:
python -m ensurepip --default-pip
There are also additional resources
for Installing pip
Here is my problem: I need to distribute Python packages that I created. I would like to create wheels, as this is now the preferred way of distributing Python packages.
On my machine: no problem.
On my client server, however, I do not have control over the Python (3.6.3) used to create the wheels. And - surprise! - the wheel package is not included by default in Python 3.6!
And yes, I know I can do: sudo pip install wheel but I do not have sudo rights in that environment.
I could create a virtualenv, install wheel in that virtual environment, ans then create my packages (and I will probably end up doing just that), but what a pain in the neck!!
Am I missing something here?
If not, there is an inconsistency, in my mind: on the one hand, we are told to use wheels, but on the other hand the "preferred" mechanism is not available in a vanilla Python (at least in Python 3.6)
Any thoughts on that?
There is a an intermediate between installing packages system-wise via sudo pip and installing in virtual environment: install packages for your user!
$ pip --user install --upgrade pip wheel
(in some platforms pip automatically selects --user when invoked without sudo)
Packages that ship binaries (such as pip and wheel) will have them installed by default at ~/.local/bin, so make sure that dir is in your $PATH. The default /etc/profile or ~/.profile in most distros already do that if dir exists, so you might have to logout/login once for $PATH to be updated after installing your first package.
Now you can enjoy wheel (and latest pip) just like as if they were any other system package, and without any the of trouble of dealing with virtualenvs.
I was informed that if I have installed anaconda to organize python then I would better install using:
conda install mypackage
rather than
pip3 install mypackage
Is that true? if that is true, can anyone tell some reason for that? version inconsistent or hard to maintain?
You can install your packages with both conda and pip, all of them would work well. The only difference is that conda is Anaconda's package manager, while pip is Python package manager, so there could be some version incompabilities between the packages, installed from different packages into one virtual environment.
Actually there are some difference here:
conda install will install package in your venv environment when you are install under some environment.which may be some thing like: d:/.../venv
while
pip install will install package in some system folder, in my computer is like c:/users/.../
you can definitely change the order of the path in your sys.path to decide which version of package you can use, if you have more than one version installed(if you install numpy
using both conda install and pip install then you may get two versions in two different folders)
There may be some way to put the installed package from pip also in venv folder, I am trying to find it.
I installed python via brew, and made it my default python. If I run which python, I obtain /usr/local/bin/python. Also pip is installed via brew, which pip returns /usr/local/bin/pip.
I do not remember how I installed ipython, but I didn't do it via brew, since when I type which ipython, I obtain /opt/local/bin/ipython. Is it the OS X version of ipython?
I installed all libraries on this version of ipython, for example I have matplotlib on ipython but not on python. I do not want to re-install everything again on the brew python, rather continue to install libraries on this version of ipython. How can I install new libraries there? For example, Python Image Library, or libjpeg?
If possible, I would like an exhaustive answer so to understand my problem, and not just a quick fix tip.
I installed python via brew, and made it my default python. If I run which python, I obtain /usr/local/bin/python.
Okay, good so far.
Also pip is installed via brew, which pip returns /usr/local/bin/pip.
Actually, not quite brew install python would have installed pip because even doing brew search pip comes up with this warning.
If you meant "pip" precisely:
Homebrew provides pip via: `brew install python`. However you will then
have two Pythons installed on your Mac, so alternatively you can install
pip via the instructions at:
https://pip.readthedocs.io/en/stable/installing/
So, Python came with pip, not brew install
when I type which ipython, I obtain /opt/local/bin/ipython. Is it the OSX version of ipython?
There is no "OSX version of ipython"...
I installed all libraries on this version of ipython, for example I have matplotlib on ipython but not on python.
You actually did install them to your brew installed Python. IPython is not a new installation of Python.
You can even start a python interpreter from the terminal and import matplotlib to check this
I do not want to re-install everything again on the brew python
What exactly needs re-installed? It's already installed into the brew python
To transfer all your packages you can use pip to freeze all of your packages installed in ipython and then install them all easily from the file that you put them in.
pip freeze > requirements.txt
then to install them from the file pip install -r requirements.txt
I'm not entirely sure if I understood what you're asking so if this isn't what you want to do please tell me.
OK, so I solved by uninstalling macport (and so the ipython I was using, which was under /opt/local/bin) and installing ipython via pip. Then I re-install what I needed (e.g. jupyter) via pip.
So I heard about the proper way to install packages into python by creating a new virtual environment for every project. Being on a mac (10.8) I have installed python3 using Homebrew, then I installed pip and virtualenv on this copy.
Now here comes the problem:
I create a new virtualenv, and activate it using:
virtualenv testing
source testing/bin/activate
When I type
which python
/Users/mik/Desktop/testing/bin/python
But typing
which pip
/usr/local/bin/pip
(learned of this when trying to install a package in the virtual environment, and it installed in the system wide installation in /usr/local/)
Inside the folder testing there is no file referring to pip
Extra Question: How does pip know which python to install the files to, for example pip list (which I believe refers to python 2.7) outputs the names of packages installed on python 3.3
I'll start with the last question as it explains what is happening.
The commands pip and easy_install are python scripts which are made executable on the filesystem. The python they use is the python that the first line tells to run the script. e.g. in /usr/bin/easy_install it is #!/usr/bin/python This will be Apple's python. So easy_install will install the 2.7 version of pip and virtualenv and will ignore your python3.3 setup.
The way to instal into python 3 is to install the 3.3 version of pip and virtualenv, the easiest way would be to install the Homebrew package for them. I think it is easier and less confusing to use just one package manager (Homebrew here) and not two (i.e. Homebrew and python).
You can also install easy_install directly. The way to do this is install the distribute package using python3.3 explicitly.
Python 3.4 will make this much easier as pip will always be available