The README, a tool made in Ruby or Python, often contains simple commands such as gem install redcarpet or pip install pygments as an installation method.
However, when looking at this installation method, people who are not familiar with Ruby say, "I get an error that I do not understand even if I gem install anyway, and if I complain, it seems that it is better not to use bundler", Python If you're new to Ruby, you might wonder, "Where do you install this? Isn't it like bundler?"
At least I didn't like the tools that gem install installs. But it would be different to complain, "That's why gem is ...", I thought Rubyist would have the same feelings for pip install, so I decided to write this article for someone like me. You may have a wrong understanding of the tools on the Ruby side, so if you make a mistake, please make an edit request.
gem install and pip installBoth are used to install third-party packages.
User-independent, usually /usr/local/lib/ruby/gems/2.3.0 for Ruby and /usr/local/lib/python3.5/site-packages/ for Python Attempts to install in location.
gem install --user-install <package name> or pip install --user <package name>, then ~ / .gem / ruby / 2.3.0 or ~ / .local / lib / python3. Install it in a location like 5 ( ~ / Library / Python / 3.5 / lib / python / site-packages if maxOS is Framework".
Note: Pip, which can be installed on Ubuntu with ʻapt install python3-pip`, is customized to automatically install with --user if you don't have sudo.
bundle install and pip install -rBoth are used to install the list of defined packages.
For bundler, bundle install will install the package based on Gemfile (if Gemfile.lock is missing or Gemfile has been updated), and the actual installed package (Gemfile) Generates a Gemfile.lock that describes the version (including dependent packages not included in). If you already have Gemfile.lock, you can install it based on it so that you can install the exact same version of the library in different environments.
For pip, pip install -r requirements.txt will also install the package according to the rules in requirements.txt. If you want to lock a version, you can do pip freeze> requirements.lock to export all currently installed libraries and versions, and then pip install -r requirements.lock.
While bundler recommends that Gemfile.lock be automatically generated and included in version control, pip does not automatically create a lock file and does not recommend a specific approach.
If you want to deploy the web application in the same way in CI and production environment, follow the same policy as bundler, and if you are a project to develop a library and just install the tools used for development, you only need requirements.txt is enough. That's why there is no equivalent to Gemfile.lock in OSS framework and library repositories.
--path and venvUse bundle install --path = vendor / bundle or python3 -m venv / path / to / python if you want to manage the libraries you want to install application-specifically rather than sharing them across Ruby or Python. ..
They have the same purpose, but they have different implementation methods, so be careful.
bundle install --path just installs the package under the specified directory.
You cannot use the packages under that directory as they are, but you can use them with the bundle exec command.
On the other hand, python3 -m venv / path / to / python creates a" virtual environment "that behaves as if you had a new Python installed in / path / to / python. Although this virtual environment has separate third-party packages, the standard library uses the original Python stuff, so it's as light as the bundler path.
Since venv only creates a virtual environment, you need to use pip in that environment to do pip install -r requirements.txt to even install it for bundle install --path.
When you execute commands in a virtual environment like this, you are executing commands in / path / to / python / bin instead of using commands like bundle exec. There are several ways to do this.
/ path / to / python / bin / pip install -r requiremnts.txt: source / path / to / python / bin / activate; pip install -r requirements.txt`The ʻactivate` script does three main things.
deactivate command that restores PATH etc.This article does not discuss which is better.
If you're used to one, you can't do the same thing with the other, which can be a hassle, so be patient if you want to dissipate the unfamiliar.
Recommended Posts