ubuntu的kylin16版本安装OpenAI gym

参考链接:

Vmware Ubuntu kylin NAT模式上网设置_y4ung-CSDN博客

ubuntu16.04纯净版-安装Python3.8.1/升级pip - 王钰 - 博客园 (cnblogs.com)

ubuntu python3 pip报错SyntaxError: invalid syntax_海棠花未眠的博客-CSDN博客

虚拟机安装不赘述了,使用版本为ubuntukylin-16.04-desktop-amd64(建议使用ubuntu而不是centos)。

安装过程很容易,按着顺序依次确定即可,安装完成之后需要进行网络配置,让我们的虚拟机链接上网络。

一、配置网络

1.打开VMware workstation ,菜单栏选项–>编辑–>虚拟网络编辑器,将VMnet8设置为NAT模式,启动DHCP(DHCP就是用来动态分配虚拟机IP的,不启用也没有关系), 如图:

1

2.在主机上开启NAT服务和DHCP服务

win+r –> services.msc

2

3.然后,打开VMware workstation ,菜单栏选项–>虚拟机–>设置为NAT模式

3

4.更改适配器设置,将可以上网的网络设置为共享,共享给虚拟机的VMnet8(不需要勾下面的勾):

4

二、配置Python3环境

ubuntu的kylin16系统自己带了Python2.7和Python3.5环境,我需要使用Python3.8+。

1.配置依赖环境,如果不进行这步可能会出现一些问题。

5

2.去官网下载Python-3.8.1.tar.xz

6

3.解压下载的包

tar -xvJf  Python-3.8.1.tar.xz

7

4.进入解压后的目录

cd Python-3.8.1/

5.安装依赖(非必要,可跳过此步骤,如在6步出错在执行本步骤)

执行下列命令安装依赖过程中,如有提示,一律y。

sudo apt-get install python-dev
sudo apt-get install libffi-dev
sudo apt-get install libssl-dev
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev

6.执行安装

./configure prefix=/usr/local/python3
sudo make && sudo make install

7.修改软连接(配置全局变量)

将原来的链接备份。

sudo mv /usr/bin/python /usr/bin/python.bak

添加python3的软链接。

sudo ln -s /usr/local/python3/bin/python3 /usr/bin/python

测试是否安装成功了。

python -V

8

8.安装/升级pip

这句是给(python2.7安装pip)

sudo apt-get install python-pip

给python3安装pip。

sudo apt-get install python3-pip

执行升级。

sudo pip install --upgrade pip
sudo pip3 install --upgrade pip

升级pip时出现了问题:

Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    from pip import main

修改一下pip配置

sudo vi /usr/bin/pip

改成

#原PIP配置文件
from pip import main  
if __name__ == '__main__':  
    sys.exit(main()) 

#修改为
from pip import __main__  //修改
if __name__ == '__main__':  
    sys.exit(__main__._main())//修改

9.pip3安装包时出现问题

Traceback (most recent call last):
  File "/usr/bin/pip3", line 11, in <module>
    sys.exit(main())
  File "/home/fulequn/.local/lib/python3.5/site-packages/pip/__init__.py", line 11, in main
    from pip._internal.utils.entrypoints import _wrapper
  File "/home/fulequn/.local/lib/python3.5/site-packages/pip/_internal/utils/entrypoints.py", line 4, in <module>
    from pip._internal.cli.main import main
  File "/home/fulequn/.local/lib/python3.5/site-packages/pip/_internal/cli/main.py", line 57
    sys.stderr.write(f"ERROR: {exc}")

原因

查了很多,大多数老外的说法是,高版本的pip不再支持python3.5

解决

移除pip的相关文件

sudo apt autoremove

下载pip的安装文件

url -O https://bootstrap.pypa.io/pip/3.5/get-pip.py

执行安装文件

/usr/bin/python3 get-pip.py

这句是给(python2.7安装pip)

sudo apt-get install python-pip

给python3安装pip。

sudo apt-get install python3-pip

pip升级

sudo pip install --upgrade pip
sudo pip3 install --upgrade pip

这个部分我卸载之后,出现了pip不存在的错误。之后重新安装,再升级就解决了。

三、安装OpenAI gym

输入下面语句,安装gym

pip install gym -i https://pypi.tuna.tsinghua.edu.cn/simple

1.出现下面错误

ModuleNotFoundError: No module named '_ctypes'

解决:

sudo apt install libffi-dev -y

2.出现错误

ERROR: No matching distribution found for gym[all]

未解决

3.出现错误

    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-n_xs68fh/mujoco-py_a3733903fc69448b995da4444e4157b9/setup.py'"'"'; __file__='"'"'/tmp/pip-install-n_xs68fh/mujoco-py_a3733903fc69448b995da4444e4157b9/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-cqfhnl92/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/fulequn/.local/include/python3.8/mujoco-py
         cwd: /tmp/pip-install-n_xs68fh/mujoco-py_a3733903fc69448b995da4444e4157b9/
    Complete output (58 lines):
    running install
    /home/fulequn/.local/lib/python3.8/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
      warnings.warn(
    running build
    
    You appear to be missing MuJoCo.  We expected to find the file here: /home/fulequn/.mujoco/mjpro150
    
    This package only provides python bindings, the library must be installed separately.
    
    Please follow the instructions on the README to install MuJoCo
    
        https://github.com/openai/mujoco-py#install-mujoco
    
    Which can be downloaded from the website
    
        https://www.roboti.us/index.html
    
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-n_xs68fh/mujoco-py_a3733903fc69448b995da4444e4157b9/setup.py", line 32, in <module>
        setup(
      File "/home/fulequn/.local/lib/python3.8/site-packages/setuptools/__init__.py", line 153, in setup
        return distutils.core.setup(**attrs)
      File "/usr/local/python3/lib/python3.8/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/usr/local/python3/lib/python3.8/distutils/dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "/usr/local/python3/lib/python3.8/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/home/fulequn/.local/lib/python3.8/site-packages/setuptools/command/install.py", line 68, in run
        return orig.install.run(self)
      File "/usr/local/python3/lib/python3.8/distutils/command/install.py", line 545, in run
        self.run_command('build')
      File "/usr/local/python3/lib/python3.8/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/usr/local/python3/lib/python3.8/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/tmp/pip-install-n_xs68fh/mujoco-py_a3733903fc69448b995da4444e4157b9/setup.py", line 28, in run
        import mujoco_py  # noqa: force build
      File "/tmp/pip-install-n_xs68fh/mujoco-py_a3733903fc69448b995da4444e4157b9/mujoco_py/__init__.py", line 3, in <module>
        from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException
      File "/tmp/pip-install-n_xs68fh/mujoco-py_a3733903fc69448b995da4444e4157b9/mujoco_py/builder.py", line 502, in <module>
        mjpro_path, key_path = discover_mujoco()
      File "/tmp/pip-install-n_xs68fh/mujoco-py_a3733903fc69448b995da4444e4157b9/mujoco_py/utils.py", line 93, in discover_mujoco
        raise Exception(message)
    Exception:
    You appear to be missing MuJoCo.  We expected to find the file here: /home/fulequn/.mujoco/mjpro150
    
    This package only provides python bindings, the library must be installed separately.
    
    Please follow the instructions on the README to install MuJoCo
    
        https://github.com/openai/mujoco-py#install-mujoco
    
    Which can be downloaded from the website
    
        https://www.roboti.us/index.html
    
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-n_xs68fh/mujoco-py_a3733903fc69448b995da4444e4157b9/setup.py'"'"'; __file__='"'"'/tmp/pip-install-n_xs68fh/mujoco-py_a3733903fc69448b995da4444e4157b9/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-cqfhnl92/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/fulequn/.local/include/python3.8/mujoco-py Check the logs for full command output.

未解决

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值