如何安装python3.6_python3.6如何安装libtorrent?

1586010002-jmsa.png

Does libtorrent support python3 now? if supported how to install it .

I want to code a DHT Crawler with python3 , i don't know why my code alaways got Connection reset by peer error , so i want to use libtorrent , if there are another lib , i'm happy to use it . My biggest problem is , conversing the infohash to torrent file . Could it be a code problem?

class Crawler(Maga):

async def handler(self, infohash, addr):

fetchMetadata(infohash, addr)

def fetchMetadata(infohash, addr, timeout=5):

tcpServer = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

tcpServer.settimeout(timeout)

if tcpServer.connect_ex(addr) == 0:

try:

# handshake

send_handshake(tcpServer, infohash)

packet = tcpServer.recv(4096)

# handshake error

if not check_handshake(packet, infohash):

return

# ext handshake

send_ext_handshake(tcpServer)

packet = tcpServer.recv(4096)

# get ut_metadata and metadata_size

ut_metadata, metadata_size = get_ut_metadata(packet), get_metadata_size(packet)

# request each piece of metadata

metadata = []

for piece in range(int(math.ceil(metadata_size / (16.0 * 1024)))):

request_metadata(tcpServer, ut_metadata, piece)

packet = recvall(tcpServer, timeout) # the_socket.recv(1024*17) #

metadata.append(packet[packet.index("ee") + 2:])

metadata = "".join(metadata)

logging.info(bencoder.bdecode(metadata))

except ConnectionResetError as e:

logging.error(e)

except Exception as e:

logging.error(e)

finally:

tcpServer.close()

解决方案

Yes, libtorrent (is supposed to) support python 3.

The basic way to build and install the python binding is by running the setup.py. That requires that all dependencies are properly installed where distutils expects them though. If this works it's probably the simplest way so it's worth a shot. I believe you'll have to invoke this python script using python3, if that's what you're building for.

To build using the main build system (and install the resulting module manually) you can follow the steps in the .travis file (for unix) or the appeyor file for windows.

In your case you want to specify a 3.x version of python, but the essence of it is:

brew install boost-python

echo "using python : 2.7 ;" >> ~/user-config.jam

cd bindings/python

bjam -j3 stage_module libtorrent-link=static boost-link=static

To test:

python test.py

Note, in the actual build step you may want to link shared against boost if you already have that installed, and shared against libtorrent if you have that installed, or will install it too.

On windows:

add the following to $HOMEPATH\user-config.jam:

using msvc : 14.0 ;

using gcc : : : -std=c++11 ;

using python : 3.5 : c:\\Python35-x64 : c:\\Python35-x64\\include : c:\\Python35-x64\\libs ;

Then run:

b2.exe --hash openssl-version=pre1.1 link=shared libtorrent-link=shared stage_module stage_dependencies

To test:

c:\Python35-x64\python.exe test.py

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值