Why install with conda even though pip can be used in Anaconda's virtual environment? I was wondering and wanted to know if there was a proper use.
pip
and conda
It was written in an easy-to-understand manner on StackOverflow and the anaconda blog. https://stackoverflow.com/questions/20994716/what-is-the-difference-between-pip-and-conda https://www.anaconda.com/understanding-conda-and-pip/
--In the case of pip, only packages made only with Python can be installed. --If you need a library written in C / C ++ or R language such as HDF5 or LLVM, you need to install it separately. --For conda, you can also install packages written in languages other than Python. --Libraries such as NumPy and Matplotlib that needed to be built when installing from PyPI with pip can now be installed from Anaconda Cloud with conda. ――For example, ** PostgreSQL can be installed and run with conda! ** (described later) --On the contrary, the wheel format media supported by pip cannot be installed by conda. This will be installed using pip.
--You can't make it with pip alone. --It needs to be realized with the help of other tools such as virtualenv and pipenv. --You can make it with just conda. --If you install pip in the created virtual environment, you can use pip as well.
--For pip, try the installation in order without checking compatibility. --Depending on the order of installation, compatibility may not be maintained and installation may occur, destroying the environment. --In the case of conda, it checks compatibility and tells you the result. --As long as the dependent library related meta information of the package to be installed is correct, conda will take care not to damage the environment.
As a test, install PostgreSQL with anaconda and try connecting.
Click here for the reference gist. https://gist.github.com/gwangjinkim/f13bf596fefa7db7d31c22efd1627c7a
$ conda create --name myenv
# enter the environment
$ conda activate myenv
$ conda install -y -c conda-forge postgresql
Initialize with the mylocal_db
folder as the data folder.
$ initdb -D mylocal_db
...
Success. You can now start the database server using:
pg_ctl -D mylocal_db -l logfile start
I will start it immediately. Depending on the added option, the operation is as follows.
--The data folder (-D
) is the initialized mylocal_db
folder.
--Log file (-l
) is output to logfile
--Use port 5433 (-p 5433
) as an option (-o
).
$ pg_ctl -D mylocal_db -l logfile -o "-p 5433" start
waiting for server to start.... done
server started
By executing the psql command, you can execute SQL.
$ psql -d postgres -p 5433
psql (11.2)
Type "help" for help.
postgres=#
Execute the stop command (pg_ctl stop) in the same way as the start command (pg_ctl start).
$ pg_ctl -D mylocal_db -l logfile -o "-p 5433" stop
waiting for server to shut down.... done
server stopped
I understand that there are some more convenient cases to install with conda:
--When using a library such as Numpy that needs to be built for each environment in C / C ++ at the time of installation --When using other middleware such as PostgreSQL is a prerequisite ――Is it possible to create a development environment where everything can be completed with just one Anaconda without having to bring out Docker (?)
On the contrary, there may be cases where pip is more convenient. Are many here?
--If you want a pure Python implementation --If the middleware you use cannot be installed with conda
Recommended Posts