virtualenv 虚拟环境使用apt的相关经验

一般来说,virtualenv中只能用pip instal 来安装三方库

但是有的三方库只能用apt-get install 来安装

相关经验:


2020年8月9日


https://stackoverflow.com/questions/15661384/python-does-not-see-pygraphviz

这个是关于import gv出错的问题

开始发现 pip install pygraphviz 无法安装,sudo pip 也不行

后来这个帖子里面指出,执行以下就行,理由是这是pygraphviz自身的问题,呵呵

sudo apt-get install -y graphviz libgraphviz-dev pkg-config python-pip

sudo pip install pygraphviz


2020年8月9日


另外,https://askubuntu.com/questions/581648/install-package-into-virtualenv-using-apt-get

这个帖子里面说:

Another alternative is to download the file with apt-get download, extract it with dpkg -x and to move the extracted files to your virtualenv:

Example:

apt-get download python-xyz

assume this results in:

./python-xyz_1.2.3-3ubuntu5_amd64.deb

Then, use dpkg to extract the data portion of the .deb file:

dpkg -x python-xyz_1.2.3-3ubuntu5_amd64.deb ./xyz-tmp

In the newly created ./xyz-tmp directory, you now have all files that would have been installed to / (root) had you used apt-get install.

Assume they are:

./xyz-tmp/usr/lib/python2.7/dist-packages/xyz/

./xyz-tmp/usr/lib/python2.7/dist-packages/xyz-1.2.3.egg-info

You still need to map the subdirectories (e.g. dist-packages vs. site-packages), and can then move the files into your virtualenv (assuming a virtualenv /home/user/.virtualenvs/py27):

mv ./xyz-tmp/usr/lib/python2.7/dist-packages/* /home/user/.virtualenvs/py27/lib/python2.7/site-packages/

Compared to my previous answer, this approach has the advantage that you don't have to research which files got installed, because you can see them in the extraction directory. It still requires a mapping of directories between the extracted archive and the virtualenv.


©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容