2016-09-04 55 views
1

注模塊:我已經請與同樣的錯誤問題,因爲我的,但我的是不同的,我想問問,如果「clean_string,clean_number,clean_text,clean_float,clean_int」蟒蛇:導入錯誤:沒有名爲utils與clean_string

agency_id = scrapy.Field(serializer=clean_string)

一些在建的Python功能或我不得不進口,使其工作

我在Python新只是在做一些編程的東西。

下面我我的代碼片段

from .utils import clean_string, clean_number, clean_text, clean_float, clean_int 
from six.moves.urllib.parse import urljoin 

class MyItem(scrapy.Item): 
    # define the fields for your item here like: 
    # name = scrapy.Field() 
    agency_id = scrapy.Field(serializer=clean_string) 

當我運行上面的代碼給我錯誤

**ImportError: No module named utils** 

你可以用它幫助我已安裝clean_string什麼

+2

的可能重複[導入錯誤:沒有模塊名爲「UTIL」(http://stackoverflow.com/questions/29957477/importerror-no-module-named-util) – thesonyman101

+0

哎我的問題是不同的請檢查:clean_string – pcoder

+0

請查看http://nullege.com/codes/show/[email protected]@[email protected]@[email protected]@[email protected]@[email protected]/11/ utils.clean_string – thesonyman101

回答

0

根據我們的討論,請安裝python -m pip install pyes

做如下:

from pyes import utils 

# use it like below 
class MyItem(scrapy.Item): 
    # define the fields for your item here like: 
    # name = scrapy.Field() 
    agency_id = scrapy.Field(serializer=utils.clean_string) 

(或)

from pyes.utils import clean_string 

# use it like below 
class MyItem(scrapy.Item): 
    # define the fields for your item here like: 
    # name = scrapy.Field() 
    agency_id = scrapy.Field(serializer=clean_string) 

你不能使用from .utils import clean_string,因爲它在當前工作目錄中查找utils。相反,要麼使用from django import utils(或)使用from pyes.utils import clean_string

+0

如果你正在開發或編寫這個代碼作爲django網絡應用程序的一部分,我可以安裝django – pcoder

+0

。是的,你必須通過'python -m pip install django'來安裝django。 –

+0

我確實安裝了ur命令並且現在運行了代碼它給了錯誤:from django.utils import clean_string,clean_number,clean_text,clean_float,clean_int ImportError:無法導入名稱clean_string – pcoder

相關問題