Ubuntu 下安装Python2.7, Scrapy, tabula

1, 首先安装Python

安装依赖包:

apt-get install zlib-devel bzip2-devel  openssl-devel ncurses-devel

1.下载源码包,后面的下载链接直接在python官网找的,如果想安装更高的版本自行更换
wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz

2.解压压缩包

tar xvf Python-2.7.10.tgz

3.指定安装路径(Ubuntu下默认路径是‘/usr/local/bin/python2.7’)

cd Python-2.7.10
./configure --prefix=/usr/local/python2

4.编译并安装

make
make install

5. 验证

root@ubuntu: python

Python 2.7.13 (default, May  8 2018, 22:51:39) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

6.创建链接指向2.7,执行python可以看到已经指向2.7版本了

rm -f /usr/bin/python
ln -s /usr/local/python2/bin/python /usr/bin/python

2, 安装pip

1. 安装pip ,同样去python官网找的下载链接,需要setup-tools和pip两个包

wget https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
wget https://pypi.python.org/packages/84/08/c01703c62d4eda7ae0c38deeb8adb864d0c90367a4c3e4299b917ac88a39/setup-tools-36.0.1.zip#md5=57fed189bd50ffc95bbc3ca38670834b

2. 解压压缩包

tar xvf pip-9.0.1.tar.gz
unzip setup-tools-36.0.1.zip 

3. 进入各自目录,分别执行

python setup.py install

4. 安装成功之后创建pip的软链接

ln -s /usr/local/python2/bin/pip /usr/bin/pip
pip

3, 安装tabula-py(依赖于jdk1.7以上,所以需要安装jdk)

pip install tabula-py

4,优化

修改pip从国内镜像安装

vi ~/.pip/pip.conf

如果没有此文件,创建,并加入内容

[global]
#index-url=https://pypi.org/simple #国外镜像
index-url=http://mirrors.aliyun.com/pypi/simple/ #阿里镜像
#index-url = https://pypi.tuna.tsinghua.edu.cn/simple #清华镜像

[install]
trusted-host=mirrors.aliyun.com

5,问题

1. pip install tabula-py
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Collecting tabula-py
  Downloading http://mirrors.aliyun.com/pypi/packages/85/d6/f514e765dda3850f9df18ca63f2ae92ff3fe6bc195bdb536c35d8e52fcc6/tabula_py-1.1.1-py2.py3-none-any.whl (10.9MB)
    100% |████████████████████████████████| 10.9MB 1.7MB/s 
Collecting numpy (from tabula-py)
  Downloading http://mirrors.aliyun.com/pypi/packages/60/47/b62c5b0ec89d53e6347ec2914fa250d0d6bef31dac113a74b819ef7ac324/numpy-1.14.3-cp27-cp27m-manylinux1_i686.whl (8.7MB)
    100% |████████████████████████████████| 8.7MB 3.3MB/s 
Collecting requests (from tabula-py)
  Downloading http://mirrors.aliyun.com/pypi/packages/49/df/50aa1999ab9bde74656c2919d9c0c085fd2b3775fd3eca826012bef76d8c/requests-2.18.4-py2.py3-none-any.whl (88kB)
    100% |████████████████████████████████| 92kB 406kB/s 
Collecting distro (from tabula-py)
  Downloading http://mirrors.aliyun.com/pypi/packages/c1/e4/933159b5f7f9f5b7ae463e76f58da84a30d0943ab3c162c366a9ad95f01e/distro-1.2.0-py2.py3-none-any.whl
Collecting pandas (from tabula-py)
  Downloading http://mirrors.aliyun.com/pypi/packages/08/01/803834bc8a4e708aedebb133095a88a4dad9f45bbaf5ad777d2bea543c7e/pandas-0.22.0.tar.gz (11.3MB)
    100% |████████████████████████████████| 11.3MB 11.7MB/s 
 
Could not find a version that satisfies the requirement numpy==1.9.3 (from versions: 1.11.1rc1, 1.11.1, 1.11.2rc1, 1.11.2, 1.11.3, 1.12.0b1, 1.12.0rc1, 1.12.0rc2, 1.12.0, 1.12.1rc1, 1.12.1, 1.13.0rc1, 1.13.0rc2, 1.13.0, 1.13.1, 1.13.3, 1.14.0rc1, 1.14.0, 1.14.1, 1.14.2, 1.14.3)

No matching distribution found for numpy==1.9.3

解决办法:

下载安装pandas-0.22.0之后进行tabula-py的安装

2. ImportError: No module named _sqlite3

解决办法:

sudo apt-get install libsqlite3-dev 

sudo apt-get install sqlite3

重新make python文件:

./configure --enable-loadable-sqlite-extensions && make && sudo make install

3. 编码问题

https://www.cnblogs.com/fclbky/articles/4175788.html

猜你喜欢

转载自blog.csdn.net/csnd_one/article/details/80251561