Installing a list of packages in OPAM - installation

OPAM is a great Package Manager for OCaml.
Is there a way to install a given list of packages like pip does in Python (with the command pip -r requirements.txt)?
We have a small Git repo shared with several people and it would be nice to just install all project dependencies in one go.
And yes, we might have a little shell script or list the packages in a .txt file and pipe it to opam install ... but there might be a better solution.
Thanks

Assuming you have your dependencies specified in NAME.opam (or just opam) file in your project, you can run
opam install . --deps-only
This will install all dependencies for your package (or packages if you have several opam files in your project).
By default opam ignores uncommitted changes, so if you want to run this command with modified opam files you'll need to add --working-dir.
Optionally you could lock down versions of dependencies used by running opam lock, this will create .opam.locked files. opam-lock is a separate plugin in 2.0.5 (and likely until 2.1), so opam will prompt to install it.
With lock files present, you should also add --locked to opam install to ask it to use lock file and install exactly the same versions.
I would also recommend adding -j X where X is the number of cores you have available, that will speed things up.
I typically have the following in my Makefiles:
deps:
opam install . --deps-only --locked --working-dir
The syntax of .opam files is described here

Related

My bash doesn't find Conan C/C++ package manager installed with pip

Exploring StackOverflow I found the Conan package manager for C/C++. I immediately wanted to try it out.
So I installed pip and the conan package as the official guide recommends, but then, when I tried to run the package, my bash said
$ conan
bash: conan: command not found
So now I wonder how to use pip packages, specifically Conan, on Arch Linux without using AUR
EDIT
For the people who are saying in the comments that I have to write the whole path
There is no doubt about that. It would work.
But also in the conan installation documentation the recommended way to install conan is with pip and in the getting started of the same documentation, the conan package is invoked as a program (apparently placed somewhere already reachable from my PATH).
In the pip documentation, it never seems to me that the need to add the package path in the PATH variable is ever mentioned (which by the way includes the python version, so after the next python update I should update the PATH variable as well in order to continue to use the installed pip packages).
For the people that are saying that this question is not releated to conan
Since I was trying to install and run conan in the recommended way, I thought that could be a conan documentation related question. Of course installing conan from AUR worked but is not the recommended way shown in the official conan documentation. Of course using AUR is a way to do that in my operative system but is a less portable solution
$ sudo pacman -Syu python-pip
$ pip install conan
$ pip -V
pip 20.3.1 from /usr/lib/python3.9/site-packages/pip (python 3.9)
$ python -V
Python 3.9.2
$ python -c "import conan; print(conan)"
<module 'conan' from '/home/anto/.local/lib/python3.9/site-packages/conan/__init__.py'>

What's the difference between installing Yarn from npm, Homebrew, and from source?

I read that on OS X you can install Yarn either by
curl -o- -L https://yarnpkg.com/install.sh | bash
brew install yarn
npm i -g yarn
What functional difference is there between these three methods? Why would someone choose one over the others?
when using brew to install packages, you install them system wide. that is, you cannot have more than one version for the same package, which is usually problematic. for this reason, many other technologies have spawn, such as docker, snap.
moreover, each package manager has its own lifecycle and packs original package in a different manner for ease of use, distribution and maintenance. for instance, npm container is based on the release of npm package itself.
usually, you should stick to the package manager of the same ecosystem that you are using. specifically to your case, it will be recommended to use npm to install and update your package (using package.json). which will give each of your project to pin and lock the desired yarn version that you like, without any affecting your system wide.
speaking of npm, you might wish to look at this answer
curl downloads the installation script from yarnpkg.com, and installs yarn using that script
brew is a package manager for MacOS. It's meant to make things easier for people when installing commands for the terminal. When you install with brew, the package get's put into /usr/local/bin instead of /usr/bin so I believe that this is kind of like a virtual environment, and yarn wouldn't be installed into the core of your machine. You'll have to install homebrew before you can use it, and you install it using curl. I believe that there is less risk when using homebrew because of the reasons that it is kind of like a virtual environment
npm is a package manager for javascript, it's the same as yarn. It's meant for easy installation of javascript packages.
I use brew for all installs to the terminal, and npm for all installs of javascript packages.

Automatically install pip packages' OS dependencies

I am installing lots of pip packages on a debootstrap'd Debian which is understandably quite bare bones and lacks a ton of packages that you'd usually expect on a regular installation. Naturally, pip installations are failing because the OS doesn't have the libraries they depend on.
Instead of individually digging for dependencies I need to install, is there a way to let pip resolve apt dependencies?
No. pip is a portable tool designed to be run on many operating systems. But on every operating system pip works with just Python packages and doesn't touch system libraries. If you install Python packages with apt or any other distribution-specific package manager it handles all dependencies. When you add pip to the toolbox — you are on your own.

What is the difference between pip install and pip download?

What is the difference between pip install and pip download?
$ pip --version
pip 9.0.1 from c:\users\nahawk\python\python27\lib\site-packages (python 2.7)
I did a diff on the help for the 2 commands and it wasn't very helpful. Unfortunately, the options are listed in a little different order, which makes them look more different that they actually are.
pip help download
pip help install
I found the answer in the online docs for pip download.
IMO, some of this should be stated in the help (i.e. in the description). Otherwise, how would one know how to use it, using pip help download?
pip download replaces the --download option to pip install, which is
now deprecated and will be removed in pip 10.
pip download does the same resolution and downloading as pip install,
but instead of installing the dependencies, it collects the downloaded
distributions into the directory provided (defaulting to the current
directory). This directory can later be passed as the value to pip
install --find-links to facilitate offline or locked down package
installation.
pip download with the --platform, --python-version, --implementation,
and --abi options provides the ability to fetch dependencies for an
interpreter and system other than the ones that pip is running on.
--only-binary=:all: is required when using any of these options. It is important to note that these options all default to the current
system/interpreter, and not to the most restrictive constraints (e.g.
platform any, abi none, etc). To avoid fetching dependencies that
happen to match the constraint of the current interpreter (but not
your target one), it is recommended to specify all of these options if
you are specifying one of them. Generic dependencies (e.g. universal
wheels, or dependencies with no platform, abi, or implementation
constraints) will still match an over- constrained download
requirement.

How to install an external package to /usr/local without troubling Homebrew?

I'm trying to install a package called Geant4 by compiling from source (HomeBrew actually has the package but it's an old version and doesn't have support for Python which I need).
I want to put the Geant4 package in /usr/local/geant4 (perhaps this is not the proper place to put it in OSX?).
Now, the Homebrew FAQ has some instructions on how to install external stuff, but when I do brew diy, I get the error message:
Error: Couldn't determine build system
The command I should use to configure Geant4 is:
cd ~/my-build-directory
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/geant4 ~/Downloads/geant4.10.01.p01
brew diy makes a good effort to determine how to build a package, but it doesn't always get it right. In the case of custom packages, it's probably best to install them into $(brew --prefix)/Cellar/$package/$version, just as Homerew would -- that way, you can interact with the package using brew link, etc. You can also install it to /usr/local or anywhere you like, but mimicking Homebrew works really well.
In your case, you could probably install it with something like:
cd /my-build-directory
cmake -DCMAKE_INSTALL_PREFIX=$(brew --prefix)/Cellar/geant4/10.01.p01 ~/Downloads/geant4.10.01.p01
brew link geant4

Resources