This is idiomatic in Python:
pip freeze > requirements.txt pip install -r requirements.txt
The first command saves a list of requirements to a file. Then later you can use the command to install the requirements into your environment.
Node has npm install
, but I don't get how to I'm supposed to dump the state of my dependencies to a package.json. I Googled and found this:
npm ls | grep -E "^(├|└)─" | cut -d" " -f2 | awk '{FS = "@"; print "\""$1"\"", ":", "\""$2"\""}'
but as the author of this pipeline suggests, there's got to be a better way? What am I missing here?
I just want to dump my current deps into a package.json. As https://npmjs.org/doc/shrinkwrap.html says,
The "package.json" file is still required if you want to use "npm install".
I've skimmed the info on shrinkwrap
, but I'm not seeing how to simply accomplish this task with shrinkwrap
.
npm is the command-line interface to the npm ecosystem. It is battle-tested, surprisingly flexible, and used by hundreds of thousands of JavaScript developers every day. On the other hand, pip is detailed as "A package installer for Python". It is the package installer for Python.
Since pip freeze shows all dependencies as a flat list, finding out which are the top level packages and which packages do they depend on requires some effort. It's also tedious to resolve conflicting dependencies that could have been installed because older version of pip didn't have true dependency resolution [1].
The format of pip freeze is the format for requirements. txt , which is a configuration file for installing packages in bulk. If you output pip freeze as a file with redirection > and use it in another environment, you can install the same packages at once.
The most common command is pip freeze > requirements. txt , which records an environment's current package list into requirements. txt. If you want to install the dependencies in a virtual environment, create and activate that environment first, then use the Install from requirements.
This is the closest I got
npm ls | grep -E "^(├|└)─" | cut -d" " -f2 | awk -v quote='"' 'BEGIN { FS = "@" } ; { print quote $1 quote,":",quote $2 quote"," }' | sed -e 's/ :/:/g'
Output is like
"bower": "1.3.12", "chai": "2.1.2", "cucumber": "0.4.8",
Still needs to trim the final trailing comma but it's pretty close!
You can create a package.json out of the currently installed package using npm init
. Then you can easily move the package.json and simply do npm install
to install the packages wherever you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With