python3、ipython3、setup-tools、pip等环境搭建详细总结

本文详细记录了在CentOS 6.5环境下安装Python 3.5及ipython的过程,包括安装依赖、编译源码、配置环境等步骤,并提供了运行验证和清理操作的方法。

第一个python脚本:

[root@backup ~]# cat helloworld.py

print("hello world")

[root@backup ~]# python helloworld.py

hello world

 

安装python3ipython整体环境,非常麻烦,不注意会经常报错,安装不成功,折腾了一天才搞定,流程记录如下:

第一步:安装python3.5

1CentOS6.5 安装Python 的依赖包

yum groupinstall "Development tools"
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

2下载Python3.5的源码包并编译

wget https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tgz
tar xf Python-3.5.0.tgz
cd Python-3.5.0
./configure --prefix=/application/python  --enable-shared
make
make install
ln –s /application/python/bin/python3  /usr/bin/python3

3、在运行Python之前需要配置库:

echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf
ldconfig

4、运行演示:

python3 --version
Python 3.5.0

5、删除编译Python时所需要的库,当然也可以不删

yum groupremove "Development tools" --remove-leaveas
yum remove zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel --remove-leaves

6、设置别名方便使用,也可以不用设置

alias py=python3

 

第二步:安装ipython3

1、需要安装setup-tools

地址:https://pypi.python.org/pypi/setuptools 

解压 unzip setuptools-36.5.0.zip

cd setuptools-36.5.0

/application/python/bin/python3 setup.py install

2、安装pip

地址:https://pypi.python.org/pypi/pip

tar xf pip-9.0.1.tar.gz

cd pip-9.0.1

/application/python/bin/python3 setup.py install

此时会在/application/python/bin下生成一个名为pip pip3 pip3.5的几个文件夹,说明pip模块已经打包进入了python环境。

3、安装python-setuptoolspython-setuptools-devel

通过yum install安装即可

4、安装ipython

地址:https://pypi.python.org/pypi/ipython

tar xf ipython-6.0.0.tar.gz

cd ipython-6.0.0

/application/python/bin/python3 setup.py install

5、配置软链接或加入系统环境变量

ln -s /application/python/bin/python3  /usr/bin/python3

ln -s /application/python/bin/ipython3  /usr/bin/ipython3

ln -s /application/python/bin/ipython  /usr/bin/ipython


本文转自  流颗星  51CTO博客,原文链接:
http://blog.51cto.com/liukexing/1969151
PS D:\science research\deep learning\core codes and datas\rl_learning> pip list Package Version ------------------------- -------------- anyio 4.6.2.post1 argon2-cffi 23.1.0 argon2-cffi-bindings 21.2.0 arrow 1.3.0 asttokens 2.4.1 async-lru 2.0.4 attrs 24.2.0 babel 2.16.0 beautifulsoup4 4.12.3 bleach 6.2.0 certifi 2024.8.30 cffi 1.17.1 charset-normalizer 3.4.0 colorama 0.4.6 comm 0.2.2 contourpy 1.3.1 cycler 0.12.1 debugpy 1.8.9 decorator 5.1.1 defusedxml 0.7.1 executing 2.1.0 fastjsonschema 2.20.0 fonttools 4.55.3 fqdn 1.5.1 h11 0.14.0 httpcore 1.0.7 httpx 0.27.2 idna 3.10 imageio 2.36.1 imageio-ffmpeg 0.5.1 ipykernel 6.29.5 ipython 8.29.0 ipywidgets 8.1.5 isoduration 20.11.0 jedi 0.19.2 Jinja2 3.1.4 json5 0.9.28 jsonpointer 3.0.0 jsonschema 4.23.0 jsonschema-specifications 2024.10.1 jupyter 1.1.1 jupyter_client 8.6.3 jupyter-console 6.6.3 jupyter_core 5.7.2 jupyter-events 0.10.0 jupyter-lsp 2.2.5 jupyter_server 2.14.2 jupyter_server_terminals 0.5.3 jupyterlab 4.2.6 jupyterlab_pygments 0.3.0 jupyterlab_server 2.27.3 jupyterlab_widgets 3.0.13 kiwisolver 1.4.7 MarkupSafe 3.0.2 matplotlib 3.10.0 matplotlib-inline 0.1.7 mistune 3.0.2 nbclient 0.10.0 nbconvert 7.16.4 nbformat 5.10.4 nest-asyncio 1.6.0 notebook 7.2.2 notebook_shim 0.2.4 numpy 2.1.3 overrides 7.7.0 packaging 24.2 pandas 2.2.3 pandocfilters 1.5.1 parso 0.8.4 pillow 11.0.0 pip 24.3.1 platformdirs 4.3.6 prometheus_client 0.21.0 prompt_toolkit 3.0.48 psutil 6.1.0 pure_eval 0.2.3 pycparser 2.22 Pygments 2.18.0 pyparsing 3.2.0 python-dateutil 2.9.0.post0 python-json-logger 2.0.7 pytz 2024.2 pywin32 308 pywinpty 2.0.14 PyYAML 6.0.2 pyzmq 26.2.0 referencing 0.35.1 requests 2.32.3 rfc3339-validator 0.1.4 rfc3986-validator 0.1.1 rpds-py 0.21.0 Send2Trash 1.8.3 setuptools 75.6.0 six 1.16.0 sniffio 1.3.1 soupsieve 2.6 terminado 0.18.1 tinycss2 1.4.0 tornado 6.4.2 traitlets 5.14.3 types-python-dateutil 2.9.0.20241003 tzdata 2024.2 uri-template 1.3.0 urllib3 2.2.3 wcwidth 0.2.13 webcolors 24.11.1 webencodings 0.5.1 websocket-client 1.8.0 widgetsnbextension 4.0.13 PS D:\science research\deep learning\core codes and datas\rl_learning> pip install gym==0.18.3 Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting gym==0.18.3 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/1a/db/816fd52c0c196b6799e89d1f65b6c74fead2707cf7d447f3f354edfa7a44/gym-0.18.3.tar.gz (1.6 MB) Installing build dependencies ... done Getting requirements to build wheel ... error error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> [3 lines of output] C:\Users\Zhang\AppData\Local\Temp\pip-build-env-ugk09oli\overlay\Lib\site-packages\setuptools\_distutils\dist.py:289: UserWarning: Unknown distribution option: 'tests_require' warnings.warn(msg) error in gym setup command: 'extras_require' must be a dictionary whose values are strings or lists of strings containing valid project/version requirement specifiers. [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. [notice] A new release of pip is available: 24.3.1 -> 25.1.1 [notice] To update, run: python.exe -m pip install --upgrade pip error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> See above for output. note: This error originates from a subprocess, and is likely not a problem with pip.
最新发布
07-15
<think>我们正在尝试安装gym==0.18.3,但遇到了构建错误,错误信息涉及`extras_require`格式问题。根据引用[1][2][3][4],我们可以总结出以下关键点: 1. 问题可能由setuptools版本过高引起(引用[1]和[3]) 2. 解决方案是降低setuptools和wheel的版本(引用[1]和[3]) 3. 引用[4]直接指出错误是`error in gym setup command: &#39;extras_require&#39; must be a dictionary whose values are strings or lists of strings ...`,这进一步证实了setuptools版本兼容性问题。 因此,解决步骤为: 步骤1:降低setuptools版本至63.2.0(引用[1]建议)或兼容版本 步骤2:降低wheel版本至0.37.0(引用[3]建议) 步骤3:安装gym==0.18.3 具体命令如下:</think>### 解决 `pip install gym==0.18.3` 的 `extras_require` 错误 #### 问题原因 该错误是由于 **setuptools 和 wheel 版本过高**与旧版 gym 0.18.3 不兼容导致。当 `extras_require` 配置不符合新版 setuptools 的格式要求时,会触发此错误[^1][^3][^4]。 $$ \text{错误根源} = \begin{cases} \text{setuptools 版本} \geq 64.0.0 \\ \text{wheel 版本} \geq 0.38.0 \end{cases} $$ --- ### 解决方案(逐步操作) #### 1️⃣ **降级 setuptools 和 wheel** ```bash # 降级 setuptools 到兼容版本 pip install setuptools==63.2.0 # 降级 wheel 到兼容版本 pip install wheel==0.37.0 ``` #### 2️⃣ **安装 gym 0.18.3** ```bash pip install gym==0.18.3 ``` #### 3️⃣ **验证安装** ```python import gym print(gym.__version__) # 应输出 0.18.3 ``` --- ### 补充说明 1. **版本兼容性** gym 0.18.3 发布于 2021 年,需搭配旧版构建工具: - Setuptools ≤ 63.2.0(推荐) - Wheel ≤ 0.37.0(推荐)[^1][^3] 2. **替代方案** 若需使用新版工具,可尝试兼容层: ```bash pip install --use-deprecated=legacy-resolver gym==0.18.3 ``` 3. **环境隔离建议** 使用虚拟环境避免影响其他项目: ```bash python -m venv gym_env source gym_env/bin/activate # Linux/macOS gym_env\Scripts\activate # Windows ``` > **注意**:部分强化学习代码(如《动手学强化学习》)需此特定版本才能正常运行[^2]。 相关问题: 1. 如何检查当前环境setuptools 和 wheel 的版本? 2. 除了 gym 0.18.3,哪些旧版 Python 包容易遇到类似构建问题? 3. 在 Docker 中如何永久固定 setuptools 和 wheel 版本?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值