本项目使用mac开发,环境配置都是基于mac的环境,python版本为2.7,IDE为PyCharm,数据库为mysql,redis,elasticsearch
下载Scrapy
- mac自带工具easy_install下载pip
- pip install scrapy
注意:mac中自带自带的python2.x的库,因此默认安装的包是不能被删除的,原因很简单:Scrapy依赖six库,但是系统的six库比较老,安装scrapy需要卸载之后安装一个新的。但是Mac OS本身也依赖six,导致无法删除,因此没有办法安装Scrapy。
Found existing installation: six 1.4.1
DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version.
This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
Uninstalling six-1.4.1:
Exception:
Traceback (most recent call last):
解决方法:使用virtualenv安装虚拟环境
sudo pip install virtualenv
//下载虚拟环境
sudo virtualenv scrapyenv
//安装一个名字为'scrapyenv'的虚拟环境
cd scrapyenv
source bin/activate
//激活虚拟环境
sudo pip install Scrapy
//下载Scrapy
- 安装路径为cd /Library/Python/2.7/site-packages/scrapyenv/bin
- 安装之后的虚拟环境中的目录结构
.
├── cache
├── plugins
│ └── pyenv-virtualenv
│ ├── bin
│ ├── etc
│ │ └── pyenv.d
│ ├── shims
│ └── test
│ ├── stubs
│ └── tmp
├── shims
└── versions
├── 3.5.1
│ ├── bin
│ ├── envs
│ │ ├── my-virtualenv-3.5.1
│ │ └── new-env-3.5.1
│ ├── include
│ │ └── python3.5m
│ ├── lib
│ │ ├── pkgconfig
│ │ └── python3.5
│ └── share
│ └── man
├── my-virtualenv-3.5.1 -> /Users/jerry/.pyenv/versions/3.5.1/envs/my-virtualenv-3.5.1
└── new-env-3.5.1 -> /Users/jerry/.pyenv/versions/3.5.1/envs/new-env-3.5.1
在PyCharm中添加解释器
- 新建一个项目
- 选择本地刚刚新建的虚拟环境
- 添加虚拟环境地址
/Library/Python/2.7/site-packages/scrapyenv/bin/python
添加成功。
指定虚拟环境中的python版本
virtualenv test --python=python3.5
为pip添加豆瓣源
https://pypi.douban.com/simple/
//豆瓣源地址
安装包时输入
pip install -i https://pypi.douban.com/simple/ xxx
// xxx为下载的包名