sublimeREPL下python 2 切换为 python 3

 python, sublime  sublimeREPL下python 2 切换为 python 3已关闭评论
7月 202020
 

转自:https://www.jianshu.com/p/41df9da08f60

1、安装python3

 

$ brew search python
$ brew install python3

这里安装完后不需要单独添加环境变量,程序已经处理好,可以直接运行python3命令。

$ which python
/usr/bin/python

$ which python3
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3

$ echo $PATH
/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

2、安装REPL插件,并设置快捷键绑定。

打开后,搜索 SublimeREPL 安装即可。

设置快捷键:

Preferences -> Key Bindings

[   
    {"keys":["f1"],
    "caption": "SublimeREPL: Python - RUN current file",
    "command": "run_existing_window_command", "args":
    {"id": "repl_python_run",
    "file": "config/Python/Main.sublime-menu"}},

    {"keys":["f2"],
    "caption": "SublimeREPL: Python",
    "command": "run_existing_window_command", "args":
    {"id": "repl_python",
    "file": "config/Python/Main.sublime-menu"}}
]

这里我设置的 F1 运行代码,F2 打开终端。

3、按 F2 运行终端,发现默认集成的是 python2,手动改成 pyhton3,方法如下:

$ sudo find / -iname 'Main.sublime-menu'
$ vim /Users/keithtt/Library/Application\ Support/Sublime\ Text\ 3/Packages/SublimeREPL/config/Python/Main.sublime-menu

"cmd": ["python3", "-i", "-u"],
"cmd": ["python3", "-i", "-u", "-m", "pdb", "$file_basename"],
"cmd": ["python3", "-u", "$file_basename"],
"cmd": {
    "osx": ["python3", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
    "linux": ["python3", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
    "windows": ["python3", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"]
},

将该文件中调用 python 命令的地方全部改成 python3 即可。

改完之后再次按 F2 运行终端,效果如下:

centos 7 使用pyenv 安装 python 3 出现“ModuleNotFoundError: No module named ‘_ctypes’”的问题解决

 python  centos 7 使用pyenv 安装 python 3 出现“ModuleNotFoundError: No module named ‘_ctypes’”的问题解决已关闭评论
10月 232019
 

centos 7 下使用pyenv 安装python 3.7时错误如下;

Downloading Python-3.7.4.tar.xz…
-> https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tar.xz
Installing Python-3.7.4…

BUILD FAILED (CentOS Linux 7 using python-build 20180424)

Inspect or clean up the working tree at /tmp/python-build.20191023165632.13343
Results logged to /tmp/python-build.20191023165632.13343.log

Last 10 log lines:
File “/tmp/tmpgvoc4sao/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/main_parser.py”, line 12, in <module>
File “/tmp/tmpgvoc4sao/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/commands/__init__.py”, line 6, in <module>
File “/tmp/tmpgvoc4sao/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/commands/completion.py”, line 6, in <module>
File “/tmp/tmpgvoc4sao/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/base_command.py”, line 20, in <module>
File “/tmp/tmpgvoc4sao/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/download.py”, line 37, in <module>
File “/tmp/tmpgvoc4sao/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/utils/glibc.py”, line 3, in <module>
File “/tmp/python-build.20191023165632.13343/Python-3.7.4/Lib/ctypes/__init__.py”, line 7, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named ‘_ctypes’
make: *** [install] Error 1

 

解决方法如下:

  1. 先安装: yum install libffi-devel -y
  2. 再安装python: pyenv install 3.7.4

DONE!

如果安装成功后有WARNING提示:

WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?
WARNING: The Python readline extension was not compiled. Missing the GNU readline lib?
WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib?

为避免后续使用中问题,可进一步安装其它依赖包

yum install readline readline-devel readline-static -y

yum install sqlite-devel -y

yum install bzip2-devel bzip2-libs -y

yum install openssl openssl-devel openssl-static -y

OK!!