Python3编译,Conda3安装,Conda3配置,代理,镜像
20200831 更新
好久没有编译, 几乎忘了命令和踩过的坑, 来看自己的笔记发现也没有. 真是.以后还是要多笔记一下
先安装一堆依赖
yum install gdbm-devel tk-devel xz-devel sqlite-devel readline-devel bzip2-devel ncurses-devel zlib=devel
当然gcc也是要的.
yum install gcc*
./configure --prefix=/usr/local/python3.8.5 --enable-optimizations --with-ensurepip=install
./configure prefix=/usr/local/python3.7.9 --enable-shared
#--enable-optimizations 会很慢, 如果不是生产环境, 就调过这一步吧.
#--with-ensurepip=install
#--enable-shared 这个是解决一堆编译错误的
https://www.everkb.com/article/en/failed-to-build-these-modules-_ctypes-when-installing-python-3-on-centos-7
make -j 8 make altinstall
#有一步过不去, 最后 yum install zlib-devel 就好了
20220709更新
变化很快,系统坏了,找人把服务器刷成centos8,然后今年开始centos8也不支持了,最近切换了valt的stream,又可以更新了,中间有些波折,需要狠心一下,装上新的repo,就好了。
然后开始使用python,结果发现以前build的python没有安装ssl模块,导致pip https 网站的时候不能用。而公司的pip私服今年统一上了https。
用系统自带的python3.6是可以的,说明系统安装的是没问题。
于是下载最新的python3.10.5 重新编译
主要有3种ssl选项,不知道有什么坑,用了 --with-ssl-default-suites=python --enable-optimizations --prefix=/usr/local/python3.10.5
--with-ensurepip=install --enable-shared 这2个忘了
--with-openssl=DIR root of the OpenSSL directory
--with-openssl-rpath=[DIR|auto|no]
Set runtime library directory (rpath) for OpenSSL
libraries, no (default): don't set rpath, auto:
auto-detect rpath from --with-openssl and
pkg-config, DIR: set an explicit rpath
--with-ssl-default-suites=[python|openssl|STRING]
override default cipher suites string, python: use
Python's preferred selection (default), openssl:
leave OpenSSL's defaults untouched, STRING: use a
custom string, python and STRING also set TLS 1.2 as
minimum TLS version
编译时的壮观场面,还好吧
make
然后make install
shell中设置代理的配置点:
export http_proxy=http://xxxx:80/ export ftp_proxy=http://xxxx:80/ export socks_proxy=socks://xxxx:80/ export https_proxy=http://xxxx:80/ export no_proxy=10.0.0.0/8,192.0.0.0/8,.xxxx,localhost,127.0.0.0/8,::1
基本上这篇文章是最全的
https://www.cnblogs.com/chuijingjing/p/10948260.html
安装conda, 最好选择miniconda, annaconda和系统一个annaconda居然重名,不知道系统里为什么有了一个这个东西...
安装conda最后一步需要选择No
You have chosen to not have conda modify your shell scripts at all. To activate conda's base environment in your current shell session: eval "$(/usr/local/miniconda/bin/conda shell.YOUR_SHELL_NAME hook)" To install conda's shell functions for easier access, first activate, then: conda init If you'd prefer that conda's base environment not be activated on startup, set the auto_activate_base parameter to false: conda config --set auto_activate_base false
安装miniconda就一句话, 下载shell, 然后执行shell,然而想看看这个shell的内容, 是不可能的, 因为文件太大了, 估计是合在一起的.
bash Miniconda3-latest-Linux-x86_64.sh
有几个步骤, 最后一步选择false
是交互式安装
Miniconda3 will now be installed into this location:
/root/miniconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
后来指定一个目录/usr/local/miniconda
这篇讲得详细
https://www.jianshu.com/p/fab0068a32b4
不过会修改.bashrc文件,加入一些东西.(干掉, 跟X系统中有个shell冲突了... centos里倒是可以)
自己在.profile中加入miniconda/bin, 就OK了.
使用pip3的包管理, 可能编程的时候可以使用,但是不能执行, 不清楚为什么, 留个疑问.
比如pip3 install jupyter之后, jupyter notebook是不能 用的,
使用conda install jupyter之后, 就可以用了.
pip3 show selenium 可以查到安装了那些软件
pip3包的下载目录在安装目录下/usr/local/python3.7.6/lib/python3.7/site-packages
minicoda的下载目录就在安装目录下, /usr/local/miniconda/pkgs
conda增加国内镜像
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/ conda config --set show_channel_urls yes
conda设置代理, 就直接编辑 ~/.condarc文件吧, 是yml格式的
proxy_servers: https: http://username:password@xxx.cn http: http://username:password@xxx.cn
官方的配置点: https://conda.io/projects/conda/en/latest/configuration.html
顺便扯一下其他代理: yum的代理在/etc/yum.conf
pip代理 设置:
pip install -r requirements.txt --proxy=代理服务器IP:端口号
https://www.jianshu.com/p/eab26fdcf02e
/etc/profile 会让所有应用都使用代理
export http_proxy=socks5://10.30.127.84:1080 export https_proxy=socks5://10.30.127.84:1080
终于踩完了一堆坑,然后使用ipython/jupyter
[root@xxx ~]# jupyter notebook [I 15:17:06.539 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret [C 15:17:07.012 NotebookApp] Running as root is not recommended. Use --allow-root to bypass.
[root@xxx ~]# jupyter notebook --allow-root [I 15:17:32.037 NotebookApp] Serving notebooks from local directory: /root [I 15:17:32.037 NotebookApp] The Jupyter Notebook is running at: [I 15:17:32.037 NotebookApp] http://localhost:8888/?token=xxxxx [I 15:17:32.037 NotebookApp] or http://127.0.0.1:8888/?token=xxxxx [I 15:17:32.037 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). [C 15:17:34.726 NotebookApp] To access the notebook, open this file in a browser: file:///root/.local/share/jupyter/runtime/nbserver-753-open.html Or copy and paste one of these URLs: http://localhost:8888/?token=xxxx or http://127.0.0.1:8888/?token=xxxx
[root@xxxx xxxx]# ipython Python 3.7.4 (default, Aug 13 2019, 20:35:49) Type 'copyright', 'credits' or 'license' for more information IPython 7.11.1 -- An enhanced Interactive Python. Type '?' for help. In [1]: print("hello") hello In [2]:
ipython 使用的python是自己bin目录下的python, 可能是安装的时候把当时的python copy进去了.
(?, 待验证, 因为我机器上编译完3.7.4装了miniconda, 后面又编译完3.7.6, miniconda里面的python还是python3.7.4)
[xxx@xxx bin]# ll python lrwxrwxrwx 1 root root 9 1月 2 18:55 python -> python3.7 [xxx@xxx bin]# ll python3.7 -rwxrwxrwx 2 root root 12743912 8月 14 04:43 python3.7