简体   繁体   English

如何使用pyenv在不同的python环境上安装依赖项

[英]How to install dependencies on different python environment using pyenv

I installed cmus in OSX and I run it with an awesome utility called cmus-osx.py which uses pyobjc and tinytag . 我在OSX中安装了cmus,并使用名为cmus-osx.py的强大实用程序运行它,该实用程序使用pyobjctinytag It ran perfectly with Python 2.7.11. 它与Python 2.7.11完美兼容。

But I wanted to also run mpsyt , which only works with Python 3, so I installed pyenv in order to be able to run both utilities without messing with my environment. 但是我还想运行mpsyt ,该功能仅在Python 3上有效,因此我安装了pyenv以便能够运行这两个实用程序而不会弄乱我的环境。 It worked, but it caused me some problems with cmus-osx.py, so I created an issue at the GitHub repo: https://github.com/azadkuh/cmus-osx/issues/5 . 它起作用了,但是它给我带来了cmus-osx.py的一些问题,所以我在GitHub仓库上创建了一个问题: https : //github.com/azadkuh/cmus-osx/issues/5

After some back and forward with the author, I realized that pyobjc became unavailable in any of the pyenv python environments after I installed pyenv . 在与作者pyobjc ,我意识到在安装pyenv之后,在任何pyenv python环境中pyenv Now the notifications feature, which requires pyobjc, only works correctly when I run cmus-osx.py from system python environment. 现在,需要pyobjc的通知功能仅在我从系统 python环境运行cmus-osx.py时才能正确运行。 The utility's author recommended me to 该实用程序的作者建议我

reinstall (share) dependencies (pyobjc and tinytag) on every environment who launches the cmus-osx utlity 在启动cmus-osx实用程序的每个环境上重新安装(共享)依赖项(pyobjc和tinytag)

The thing is that I've no idea how to do this. 问题是我不知道该怎么做。 I use OSX and I run cmus-osx.py from a zsh shell. 我使用OSX,并从zsh shell运行cmus-osx.py。

I know I should be able to figure it out by reading pyenv documentation, but I'm still learning to code and to manage a *nix based system and I want to understand what's really going on. 我知道我应该可以通过阅读pyenv文档来弄清楚,但是我仍在学习编码和管理基于* nix的系统,我想了解真正发生的事情。

I would suggest doing some reading on the Python Virtual Environments tool, virtualenv , such as the excellent guide here . 我建议对Python虚拟环境工具virtualenv进行一些阅读,例如此处的出色指南。

Basically the steps are: 基本上,这些步骤是:

pip install virtualenv
virtualenv some_dir_name

You can specify which exact python to install to your virtual environment with the -p flag. 您可以使用-p标志指定要安装到虚拟环境的确切python。

some_dir_name/bin/acivate

Windows users will need to use activate.bat Windows用户将需要使用activate.bat

You are then in your specified python environment with no packages other than the standard library and pip installed and can install anything that you like with pip without any risk that it will impact any of your other installations. 然后,您处于指定的python环境中,除了标准库和pip之外,没有其他软件包,并且可以使用pip安装任何您喜欢的东西,而不会影响任何其他安装。

When you are finished exit the terminal session. 完成后,退出终端会话。 If you wish to go back to that environment, with all of the libraries that you installed to it , you can just activate it again. 如果您希望返回到该环境, 并且已将所有库安装到该环境, 可以再次将其激活。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM