序言:个人使用阿里云的服务器,Ubuntu系统时在创建虚拟环境处卡住,多次修改无果后改用CentOS系统配置环境成功,但是其中也是尝试多次,这里就把自己找的能够配置成功的方法整理起来,以备后续有相关配置时,能够快速应对。

一、Ubuntu系统配置(mysql --virtualenv)

1. mysql安装

平时使用虚拟机时,基本没有太多涉及到这样的问题。就是安装前先apt-git命令升级下

sudo apt-get update

sudo apt-get install mysql-server

注:Ubuntu 最新系统自带python3不存在安装python部分,所以直接跳转到虚拟环境的安装。

2. 安装虚拟环境

安装虚拟环境报如下错误:

root@iZ2zef57ni8z6z1jo0l6flZ:/home# virtualenv django_news

Running virtualenv with interpreter /usr/bin/python2

New python executable in /home/django_news/bin/python2

Also creating executable in /home/django_news/bin/python

Please make sure you remove any previous custom paths from your /root/.pydistutils.cfg file.

Installing setuptools, pkg_resources, pip, wheel...

Complete output from command /home/django_news/bin/python2 - setuptools pkg_resources pip wheel:

Collecting setuptools

Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/66/e8/570bb5ca88a8bcd2a1db9c6246bb66615750663ffaaeada95b04ffe74e12/setuptools-40.2.0-py2.py3-none-any.whl (568kB)

Collecting pkg_resources

Exception:

Traceback (most recent call last):

File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/basecommand.py", line 209, in main

status = self.run(options, args)

File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/commands/install.py", line 328, in run

wb.build(autobuilding=True)

File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/wheel.py", line 748, in build

self.requirement_set.prepare_files(self.finder)

File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/req/req_set.py", line 360, in prepare_files

ignore_dependencies=self.ignore_dependencies))

File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/req/req_set.py", line 512, in _prepare_file

finder, self.upgrade, require_hashes)

File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/req/req_install.py", line 273, in populate_link

self.link = finder.find_requirement(self, upgrade)

File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/index.py", line 442, in find_requirement

all_candidates = self.find_all_candidates(req.name)

File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/index.py", line 400, in find_all_candidates

for page in self._get_pages(url_locations, project_name):

File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/index.py", line 545, in _get_pages

page = self._get_page(location)

File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/index.py", line 648, in _get_page

return HTMLPage.get_page(link, session=self.session)

File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/index.py", line 760, in get_page

resp.raise_for_status()

File "/home/django_news/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/models.py", line 840, in raise_for_status

raise HTTPError(http_error_msg, response=self)

HTTPError: 404 Client Error: Not Found for url: http://mirrors.cloud.aliyuncs.com/pypi/simple/pkg-resources/

----------------------------------------

...Installing setuptools, pkg_resources, pip, wheel...done.

Traceback (most recent call last):

File "/usr/lib/python3/dist-packages/virtualenv.py", line 2363, in

main()

File "/usr/lib/python3/dist-packages/virtualenv.py", line 719, in main

symlink=options.symlink)

File "/usr/lib/python3/dist-packages/virtualenv.py", line 988, in create_environment

download=download,

File "/usr/lib/python3/dist-packages/virtualenv.py", line 918, in install_wheel

call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)

File "/usr/lib/python3/dist-packages/virtualenv.py", line 812, in call_subprocess

% (cmd_desc, proc.returncode))

OSError: Command /home/django_news/bin/python2 - setuptools pkg_resources pip wheel failed with error code 2

解决办法:

查了很多资料,有部分网友说是pip源的问题,需要修改/root/.pip/pip.conf的配置文件,将其优化为如下代码:

[global]

#index-url=http://mirrors.cloud.aliyuncs.com/pypi/simple/

index-url=http://e.pypi.python.org/simple

[install]

trusted-host=mirrors.cloud.aliyuncs.com

实际执行后,进而报如下错误:

root@iZ2zef57ni8z6z1jo0l6flZ:/home/study/django# virtualenv -p python3 django_news

Already using interpreter /usr/bin/python3

Using base prefix '/usr'

New python executable in /home/study/django/django_news/bin/python3

Also creating executable in /home/study/django/django_news/bin/python

Please make sure you remove any previous custom paths from your /root/.pydistutils.cfg file.

Installing setuptools, pkg_resources, pip, wheel...done.

以上方法都不奏效,所以换为CentOS系统进行配置。

二、CentOS系统配置(python3--mkvirtualenv -- mysql)

1. python3的安装及配置

因为centos系统默认是不安装python3的所以这里如果用到python3的同学需要先安装。

python3安装配置部分,已经被大家写了很多了。所以这里不再累述。我找到了一篇这方面的博文,写的非常详细,大家可以按照这个教程进行安装。文章链接如下:

请注意:因为很多的centos系统中是没有安装zlib、zlib-devel这两个包的,所以在安装python3前,请先安装这两个包,使安装python3时关联这两个库。否则后面创建虚拟环境命令部分会报如下错误:

ps:不要问我怎么知道的,填坑的经历不忍回忆。

mkvirtualenv env3 --python=python3

Traceback (most recent call last):

File "/usr/lib/python3/bin/virtualenv.py", line 17, in

import zlib

ImportError: No module named zlib

zlib、zlib-devel模块的安装命令如下:

yum install -y zlib zlib-devel

2. 虚拟环境的安装

在保证上述的python3顺利安装完成后,开始进行接下来的虚拟环境的安装。安装步骤如下:

安装virtualenv virtualenvwrapper

pip install virtualenv virtualenvwrapper

如果没有pip 先安装

pip:yum install -y pip

安装好了之后,查找virtualenv位置:

find / -name virtualenv

例:返回:/usr/local/python3/bin/virtualenv

查找virtualenvwrapper.sh位置:find / -name virtualenvwrapper.sh

例:返回:/usr/local/python3/bin/virtualenvwrapper.sh

在/usr/bin中添加环境变量(就是新建了一个软连接) (如果bin文件下没有的话,有就可以忽略这一步)

ln -s /usr/local/python3/bin/virtualenv /usr/bin/virtualenv

修改环境变量相关脚本/root/.bashrc

添加如下代码

export WORKON_HOME=/root/.virtualenvs#创建一个存放虚拟环境的目录

export PROJECT_HOME=/root/workspace

source /usr/local/python3/bin/virtualenvwrapper.sh #virtualenvwrapper.sh的位置

然后重启:source /.bashrc

检验

输入:mkvirtualenv 查看出现的信息,如果提示命令不存在,那么就是没有安装成功

基本命令:

mkvirtualenv test #创建一个虚拟环境默认指向python3

workon test #进入test虚拟环境

deactivate #退出虚拟环境

配置完虚拟环境后,心里大爽啊,毕竟之前就是Ubuntu的虚拟环境中花了很多时间。不多说了,抓紧时间配置mysql吧。

三、安装mysql

这一类的文章也是很多了,但是我通过尝试了.gz安装包,.rpm安装包,发现后者更加简单,前者或多或少的存在这样或那样的问题,所以,这里我推荐一篇自己经过筛选实践的文章给大家。按照这个来安装简单方便。

希望大家能够快速搭建基本的环境,少花些时间在环境的配置上,有更多的时间用来提升自己!

四、安装一些包时,出现的报错情况记录

1.报错python版本与安装包不匹配

报错信息如下:

aliyun-python-sdk-core-v3 requires Python '>=3' but the running Python is 2.7.5

先使用find / -name pip3:

/usr/local/python3/bin/pip3

如果存在的话,我们进入usr/bin目录下,使用 ll pip* 命令查看下,pip都有哪些;这里会显示没有pip3命令。所以我们需要将pip3和pip3的目录连接起来:

ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

这样我们就可以使用pip3 install xxx 安装需要python3才能安装的包了。

2.安装mysqlclient等类似ORM连接的包报错

报错信息如下:

(django_news) [root@iZ2zef57ni8z6z1jo0l6flZ django_news]# pip3 install mysqlclient

Looking in indexes: http://mirrors.aliyun.com/pypi/simple/

Collecting mysqlclient

Downloading http://mirrors.aliyun.com/pypi/packages/ec/fd/83329b9d3e14f7344d1cb31f128e6dbba70c5975c9e57896815dbb1988ad/mysqlclient-1.3.13.tar.gz (90kB)

100% |████████████████████████████████| 92kB 56.9MB/s

Complete output from command python setup.py egg_info:

/bin/sh: mysql_config: command not found

Traceback (most recent call last):

File "", line 1, in

File "/tmp/pip-install-w80_hk2h/mysqlclient/setup.py", line 18, in

metadata, options = get_config()

File "/tmp/pip-install-w80_hk2h/mysqlclient/setup_posix.py", line 53, in get_config

libs = mysql_config("libs_r")

File "/tmp/pip-install-w80_hk2h/mysqlclient/setup_posix.py", line 28, in mysql_config

raise EnvironmentError("%s not found" % (mysql_config.path,))

OSError: mysql_config not found

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-w80_hk2h/mysqlclient/

解决办法:需要先安装mysql-devel, 之后再安装mysqlclient包.安装命令如下:

yum -y install mysql-devel

3.安装阿里云的包报错

报错信息如下:

(django_news) [root@iZ2zef57ni8z6z1jo0l6flZ django_news]# pip3 install aliyun-python-sdk-dysmsapi==1.0.0

Looking in indexes: http://mirrors.aliyun.com/pypi/simple/

Collecting aliyun-python-sdk-dysmsapi==1.0.0

Downloading http://mirrors.aliyun.com/pypi/packages/bb/6b/c66c776967dca765c8614feb94e3d20c32b1484549663db389692cb251ed/aliyun-python-sdk-dysmsapi-1.0.0.tar.gz

Complete output from command python setup.py egg_info:

Traceback (most recent call last):

File "", line 1, in

File "/tmp/pip-install-2hulf6co/aliyun-python-sdk-dysmsapi/setup.py", line 20, in

import ssl

File "/usr/local/python3/lib/python3.6/ssl.py", line 101, in

import _ssl # if we can't import it, let the error propagate

ModuleNotFoundError: No module named '_ssl'

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-2hulf6co/aliyun-python-sdk-dysmsapi/

即说没有安装ssl模块,然而在运行python2时是可以正常导入,但是python3就报错,不能导入ssl。

[root@iZ2zef57ni8z6z1jo0l6flZ bin]# python2

Python 2.7.5 (default, Nov 6 2016, 00:28:07)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import ssl

>>>

这里查阅了很多资料,大部分都说名要修改python3安装包的/Modules/Setup.dist或‘/Modules/Setup’文件,都是要将两个文件中的以下部分进行修改:

注意:我这里修改的/Modules/Setup.dist文件

# 原始代码

# Socket module helper for socket(2)

#_socket socketmodule.c

# Socket module helper for SSL support; you must comment out the other

# socket line above, and possibly edit the SSL variable:

#SSL=/usr/local/ssl

#_ssl _ssl.c \

#-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \

#-L$(SSL)/lib -lssl -lcrypto

#################分割线###################

# 修改后的代码

#修改结果如下:

# Socket module helper for socket(2)

_socket socketmodule.c timemodule.c # 修改部分,去掉#号,添加timemodule.c

# Socket module helper for SSL support; you must comment out the other

# socket line above, and possibly edit the SSL variable:

SSL=/usr/local/ssl # 去掉#号

_ssl _ssl.c \

-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \ # 去掉#号

-L$(SSL)/lib -lssl -lcrypto # 去掉#号

按照以上部分修改后,再一次执行如下命令:

./configure --prefix=/usr/local/python3 # 把python安装到的文件夹位置

make

make install

执行完成之后,再次运行python3,执行如下名称,查看是否成功。我这样修改后运行成功。

import ssl

# 成功导入ssl实例如下:

Python 3.6.3 (default, Sep 10 2018, 22:21:28)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> import ssl

>>>

ps:这个错误的每个部分的代码都仔细修改,如果还是不行的话,可以参考下面这个链接的方法试一下。

http://www.linuxdiyf.com/linux/32547.html

该方法主要区别时在安装时加入./configure ----with-ssl命令,有类似情况的可以试一下。

linux python虚拟环境 error_阿里云Linux系统配置python3-虚拟环境-mysql --踩坑实践(Ubuntu系统转centOS7)...相关推荐

  1. 阿里云服务器 搭建单体redis 以及踩坑

    在搭建阿里云服务器的过程中,踩坑很多,特写此文: 简介 Redis是一个开源(BSD许可),内存数据结构存储,用作数据库,缓存和消息代理.它支持数据结构,如字符串,散列,列表,集合,带有范围查询的排序 ...

  2. 阿里云天池【Docker练习场】踩坑指南

    阿里云天池[Docker练习场]踩坑指南 题目直达 提交环境搭建(基于macOS) Docker的安装与基本功能使用 Docker安装过程遇到的小问题 提交结果注意事项 提交时的镜像配置 项目结构规范 ...

  3. [CentOS Python系列] 四.阿里云服务器CentOS连接远程MySQL数据库及pymsql

    从2014年开始,作者主要写了三个Python系列文章,分别是基础知识.网络爬虫和数据分析. Python基础知识系列:Pythonj基础知识学习与提升 Python网络爬虫系列:Python爬虫之S ...

  4. 阿里云服务器SSH远程连接与踩坑小记

    当你拥有了一台云服务器,就得去玩它,要玩它的话,远程连接就太重要啦,这篇文章就主要记录怎么实现远程连接阿里云服务器: 为什么要强调一下是阿里云服务器呢?自己配置的虚拟机一般就直接用户名+密码登录,但是 ...

  5. Hexo自动部署到阿里云(Ubantu16.04)【超详细踩坑记录】

    文章目录 前言 修改Apache端口号 思路 正文 1. 服务器创建git用户 2. 服务器打开RSA认证 2.1 开启认证配置 2.2 建立ssh信任关系 3.创建blog.git空仓库 4. he ...

  6. 阿里云ECS服务_开通ipv6踩坑

    碰见公司要测试ipv6,想在阿里云ECS服务器上开启ipv6测试..   首先是从网上查<阿里云服务器开启ipv6>,发现修改配置文件,好嘛一路修改下去,也创建了Tunnel隧道.先是在C ...

  7. [CentOS Python系列] 六.阿里云搭建Django网站详解

    本篇文章主要介绍讲述部署阿里云服务器Django网站环境,并通过IP地址访问网页的过程.写代码过程中往往第一步需要解决的就是配置开发环境,对于新手来说,这是非常头疼的事情,而当配置好之后或者对于老手来 ...

  8. [CentOS Python系列] 五.阿里云部署web环境及通过IP地址访问服务器网页

    假设我们服务器CentOS系统已经部署好了,现在我们需要向服务器上传一个HTML主页,通过IP地址展示我们的内容,如何实现呢?本篇文章主要介绍讲述部署阿里云服务器web环境,并通过IP地址访问网页的过 ...

  9. Vue项目自动部署之一、阿里云Linux服务器、域名购买和使用

    购买阿里云Linux服务器 如果已有服务器请直接跳转到[传统部署方式] 登录阿里云,访问 云服务器 ECS 购买地址:https://ecs-buy.aliyun.com/ 也可从首页导航菜单进入. ...

最新文章

  1. php alert弹框按钮,PHP 实现类似js中alert() 提示框
  2. php网址中mod=,php – Apache mod-rewrite htaccess – 带参数的动态url
  3. axis2 jar包冲突_一个jar包冲突引起的StackOverflowError
  4. 数据结结构学习 ---赫夫曼树
  5. mysql c#开发库_c# 开发+MySql数据库
  6. san分布式共享文件系统_【最强科普】一文读懂分布式存储
  7. 拍照手抖有救了!DeblurGAN消除运动模糊效果惊人 | 附论文+代码
  8. python fund_Python fund-my-watcard包_程序模块 - PyPI - Python中文网
  9. apt get 安装mysql5.7_ubuntu16.04下apt-get安装mysql5.7,文件目录结构
  10. 【HDU 3038】How Many Answers Are Wrong(带权并查集,区间型)
  11. 筛选法建立初始堆_MTT法检测细胞增殖
  12. 百度地图只显示行政区
  13. 关于使用VS2015编译项目时出现LNK1112 module machine type 'x64' conflicts with target machine type 'X86'
  14. 《程序员拒绝一个合理需求的15个方法!》
  15. 使用Scratch制作打弹球游戏(一)弹球游戏过关
  16. ubuntu18.04下载安装mysql 5.7 【压缩包】
  17. 修改图书信息c语言,图书信息管理系统c语言.doc
  18. 史玉柱正式退休:把互联网留给年轻人
  19. 【BZOJ3503】【Cqoi2014】和谐矩阵 高斯消元,解异或方程组
  20. scrapy爬取海贼王漫画

热门文章

  1. [Android] Android 锁屏实现与总结 (一)
  2. Android使用MediaRecorder和Camera实现视频录制及播放功能整理
  3. 进程和线程(4)-进程 vs. 线程
  4. 《微服务设计》(一)---- 微服务
  5. Android 发送邮件信息,附带附件
  6. asp.net 中的 主从 新增,修改,删除。
  7. 很多人搞不清楚的两个类Vector,ArrayList
  8. 添加多个button或其他的控件
  9. 【转】移动Web开发-点击事件及页面滚动
  10. Ajax基础知识《一》