A few pip tips

I record these tips mainly for future references, but I would be glad if you also find this post helpful. And if you have other pip tips, please comment and I will update this post.

1. Install packages with a specific version or version range

A specific version:

pip install foo==1.2.0

Enter fullscreen mode Exit fullscreen mode

A version range:

pip install 'bar>=1.3.2,<=1.5.4'

Enter fullscreen mode Exit fullscreen mode

If the same package with a different version has already been installed, the --force-reinstall should be used.

For multiple packages, it is better to use a requirements.txt file. The syntax is just the same as the single-line version above.

foo==1.2.0
bar>=1.3.2,<=1.5.4
foobar

Enter fullscreen mode Exit fullscreen mode

Then you can run:

pip install -r requirements.txt

Enter fullscreen mode Exit fullscreen mode

2. Use a mirror when downloading packages

One-time use:

pip install -i <mirror-url> foo

Enter fullscreen mode Exit fullscreen mode

Permanent use:

pip config set global.index-url <mirror-url>

Enter fullscreen mode Exit fullscreen mode

3. Use python -m pip instead of plain pip

This will ensure that you are using the correct pip as long as you are using the correct python.

Commented by:

Kamal MustafaFollow

Python/Django Developer at Kafkai.com, AI Writer for Generating Content, Built Exclusively for SEOs and Marketers.

原文链接:A few pip tips

© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容