繁体   English   中英

使用apt-get将软件包安装到虚拟环境中

[英]Install packages into virtual environment with apt-get

我正在尝试为我的Python3项目创建一个虚拟环境。 问题是,我尝试安装到virtualenv中的某些依赖项不是通过pip来实现的。 例如,要获取LibTorrent,我必须运行: $ sudo apt-get install python3-libtorrent (LibTorrent是具有Python绑定的C ++库)。 在环境之外,我的项目运行良好。 但是在内部,我得到一个导入错误:

(env) me@Comp:~/Projects/test$ python3 main.py 
Traceback (most recent call last):
  File "main.py", line 4, in <module>
    import libtorrent as lt
ModuleNotFoundError: No module named 'libtorrent'

如果我在环境中运行$ sudo apt-get install python3-libtorrent ,它会告诉我它已经安装:

(env) me@Comp:~/Projects/test$ sudo apt-get install python3-libtorrent
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-libtorrent is already the newest version (1.1.1-1build2).
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.

我的理解是,这是因为apt-get是全局命令,与环境无关。 但是,在这种情况下,如何将这个软件包安装到我的环境中?

您设法解决问题了吗? 我遇到了同样的问题,但我偶然发现了这个问题: http : //dreamingpotato.com/2015/11/21/how-to-install-python-libtorrent-in-virtualenv/

(如果链接中断一天,则在下面复制命令)

sudo apt-get build-dep python-libtorrent
wget http://downloads.sourceforge.net/project/libtorrent/libtorrent/libtorrent-rasterbar-1.0.5.tar.gz
tar -zxvf libtorrent-rasterbar-1.0.5.tar.gz
cd libtorrent-rasterbar-1.0.5/
./configure --enable-python-binding PYTHON=`which python` --prefix=$VIRTUAL_ENV
make
make install
export LD_LIBRARY_PATH="$VIRTUAL_ENV/lib"

我的猜测是问题如下:

  1. 如您所说, python3-libtorrentpython-libtorrent只是与C ++库的python绑定/包装。
  2. 在此链接上,有一个命令可根据您使用的python路径编译lib-torrent: ./configure --enable-python-binding PYTHON=`which python` --prefix=$VIRTUAL_ENV在创建虚拟环境

因此,从理论上讲,您将必须为使用的每个virtualenv编译libtorrent。 这是一个糟糕的解决方案,但我相信它将是唯一可行的解​​决方案。 比简单的pip install -r requirements.txt糟糕。

让我知道是否对您有用,并考虑将其标记为正确答案。

暂无
暂无

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

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