Install Python2.7, Scrapy, tabula under Ubuntu

1, First install Python

Install dependencies:

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

1. Download the source code package. The download link below can be found directly on the official python website. If you want to install a higher version, replace it yourself
wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz

2. Unzip the compressed package

tar xvf Python-2.7.10.tgz

3. Specify the installation path (the default path under Ubuntu is '/usr/local/bin/python2.7')

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

4. Compile and install

make
make install

5. Verification

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. Create a link to point to 2.7, and execute python to see that it has pointed to version 2.7

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

2, install pip

1. Install pip, also go to the python official website to find the download link, you need two packages setup-tools and 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. Unzip the compressed package

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

3. Enter the respective directory and execute respectively

python setup.py install

4. After the installation is successful, create a soft link of pip

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

3, Install tabula-py (depending on jdk1.7 or above, so you need to install jdk)

pip install tabula-py

4. Optimization

Modify pip to install from domestic mirror

vi ~ / .pip / pip.conf

If this file does not exist, create it and add the content

[global]
#index-url=https://pypi.org/simple #Foreign mirror
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

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326579183&siteId=291194637