如何给python增加库_如何从不是包的自定义存储库中添加模块?Python

我试图将sys.path.append()与os.getcwd()一起使用,但是没有用.

来源来自here,我已经下载并提取了它们:

alvas@ubi:~/test$wget https://github.com/alvations/DLTK/archive/master.zip

alvas@ubi:~/test$tar xvzf master.zip

alvas@ubi:~/test$cd DLTK-master/; ls

dltk

alvas@ubi:~/test/DLTK-master$cd dltk/; ls

tokenize

alvas@ubi:~/test/DLTK-master/dltk$cd tokenize/; ls

abbrev.lex jwordsplitter-3.4.jar rbtokenize.pl

banana-split-standalone-0.4.0.jar koehn_senttokenize.pl splicer.py

igerman98_all.xml koehn_wordtokenize.pl tokenizer.py

__init__.py nonbreaking_prefix.de

alvas@ubi:~/test/DLTK-master/dltk/tokenize$cat __init__.py

from tokenizer import punct_tokenize, rb_tokenize

from tokenizer import koehn_tokenize, deupunkt_tokenize

from splicer import jwordsplitter, jwordsplitteralvas

这些是我想从?/ text /目录访问的功能,例如koehn_tokenize函数.但是我似乎无法将模块/功能添加到我的python解释器中.

alvas@ubi:~/test$wget https://github.com/alvations/DLTK/archive/master.zip

alvas@ubi:~/test$tar xvzf master.zip

alvas@ubi:~/test$python

Python 2.7.5+ (default, Sep 19 2013, 13:48:49)

[GCC 4.8.1] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import sys, os

>>> os.getcwd()

'/home/alvas/test'

>>> sys.path.append(os.path.join(os.getcwd(),'DLKT-master/dltk'))

['','/usr/local/lib/python2.7/dist-packages/...', ...,'/home/alvas/test/DLKT-master/dltk']

>>>

>>> import dltk

Traceback (most recent call last):

File "", line 1, in

ImportError: No module named dltk

>>>

>>> from dltk.tokenize import koehn_tokenize

Traceback (most recent call last):

File "", line 1, in

ImportError: No module named dltk.tokenize

在?/ test /目录的python解释器中,如何访问dltk.tokenize模块?

如果将其安装到?/ test / DLTK-master / dltk / tokenize中,则该功能有效:

alvas@ubi:~/test$cd DLTK-master/dltk/tokenize/

alvas@ubi:~/test/DLTK-master/dltk/tokenize$python

Python 2.7.5+ (default, Sep 19 2013, 13:48:49)

[GCC 4.8.1] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> from __init__ import koehn_tokenize

>>>

但是我不想在使用python解释器之前使用CD插入?/ test / DLTK-master / dltk / tokenize.我需要以某种方式在python中附加模块/功能.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值