2013-06-28 106 views
3

我想設置IMAGES_STORE爲相對路徑,但我得到錯誤,如果我指定IMAGES_STORE作爲一個完整的路徑是工作的罰款/home/vaibhav/scrapyprog/comparison/eScraperInterface/images如何設置scrapy IMAGES_STORE相對路徑

錯誤我收到是在link 其實它給我RuntimeError: OSError: [Errno 20] Not a directory: '/tmp/eScraper-1371463750-Lm8HLh.egg/images'錯誤,但如果我設置完整IMAGE_STORE路徑它工作正常可以有人告訴我如何指定相對路徑...因爲我需要在各種系統部署此項目...這就是爲什麼我需要相對路徑...

import os 
#------------------------------------------------------------------------------ 

projectDirPath = os.path.abspath(os.path.dirname((os.path.dirname(__file__)))) 
imagesDIRPath = projectDirPath + "/images" 

BOT_NAME = 'eScraper' 
DOWNLOADER_DEBUG = True 
CONCURRENT_REQUESTS = 200 
AUTOTHROTTLE_DEBUG = True 
AUTOTHROTTLE_ENABLED= True 
DEPTH_STATS_VERBOSE = True 

SPIDER_MODULES = ['eScraper.spiders'] 
NEWSPIDER_MODULE = 'eScraper.spiders' 
COMMANDS_MODULE = 'eScraper.commands' 
ITEM_PIPELINES = ['eScraper.pipelines.EscraperPipeline', 
        'eScraper.pipelines.MySQLStorePipeline'] 

IMAGES_STORE = imagesDIRPath 


DOWNLOADER_MIDDLEWARES = { 
          'eScraper.rotate_useragent.RotateUserAgentMiddleware' :400, 
          'scrapy.contrib.downloadermiddleware.useragent.UserAgentMiddleware' : None 
          } 


#------------------------------------------------------------------------------ 

我的項目結構:

├── eScraperInterface 
│   ├── build 
│   │   ├── bdist.linux-i686 
│   │   └── lib.linux-i686-2.7 
│   │    ├── eScraper 
│   │    │   ├── commands 
│   │    │   │   ├── __init__.py 
│   │    │   │   └── runAllSpiders.py 
│   │    │   ├── __init__.py 
│   │    │   ├── items.py 
│   │    │   ├── pipelines.py 
│   │    │   ├── rotate_useragent.py 
│   │    │   ├── settings.py 
│   │    │   ├── spiders 
│   │    │   └── userAgentList.py 
│   │    ├── eScraperInterface 
│   │    │   ├── __init__.py 
│   │    │   ├── settings.py 
│   │    │   ├── urls.py 
│   │    │   └── wsgi.py 
│   │    └── eScraperInterfaceApp 
│   │     ├── __init__.py 
│   │     ├── models.py 
│   │     ├── tests.py 
│   │     └── views.py 
│   ├── checkImageExist.py 
│   ├── eScraper 
│   │   ├── commands 
│   │   │   ├── __init__.py 
│   │   │   ├── __init__.pyc 
│   │   │   ├── runAllSpiders.py 
│   │   │   └── runAllSpiders.pyc 
│   │   ├── __init__.py 
│   │   ├── __init__.pyc 
│   │   ├── items.py 
│   │   ├── items.pyc 
│   │   ├── pipelines.py 
│   │   ├── pipelines.pyc 
│   │   ├── rotate_useragent.py 
│   │   ├── rotate_useragent.pyc 
│   │   ├── settings.py 
│   │   ├── settings.py~ 
│   │   ├── settings.pyc 
│   │   ├── spiders 
│   │   ├── userAgentList.py 
│   │   └── userAgentList.pyc 
│   ├── eScraperInterface 
│   │   ├── __init__.py 
│   │   ├── __init__.pyc 
│   │   ├── settings.py 
│   │   ├── settings.pyc 
│   │   ├── urls.py 
│   │   ├── urls.pyc 
│   │   ├── wsgi.py 
│   │   └── wsgi.pyc 
│   ├── eScraperInterfaceApp 
│   │   ├── __init__.py 
│   │   ├── __init__.pyc 
│   │   ├── models.py 
│   │   ├── models.py~ 
│   │   ├── models.pyc 
│   │   ├── tests.py 
│   │   └── views.py 
│   ├── images 
│   ├── __init__.py 
│   ├── manage.py 
│   ├── project.egg-info 
│   │   ├── dependency_links.txt 
│   │   ├── entry_points.txt 
│   │   ├── PKG-INFO 
│   │   ├── SOURCES.txt 
│   │   └── top_level.txt 
│   ├── scrapy.cfg 
│   └── setup.py 
├── README.txt 
└── README.txt~ 

回答

4

假設您已經從eScraperInterface/eScraper/settings.py提供settings.py

CUR_DIR = os.path.dirname(os.path.realpath(__file__)) 
IMAGES_STORE = os.path.join(CUR_DIR, '..', 'images') 

希望有所幫助。

+0

不,它沒有工作... –

+0

然後,請在問題中包括你的項目結構,謝謝。 – alecxe

+0

@ user2217267,更新了答案:現在爲'圖像'上一層。請檢查。 – alecxe

相關問題