为什么从终端和 Atom 调用时 python 的版本不同 [英] Why python's versions differ when called from Terminal and from Atom

查看:23
本文介绍了为什么从终端和 Atom 调用时 python 的版本不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从终端和 Atom 运行 Python 时,会调用不同版本的 Python.因此,有些包我可以从终端调用而不会出现问题,但我不能从 Atom 调用.详情如下:

当从 terminal 调用 python 时,我得到版本 3.7.1

$ pythonPython 3.7.1 |由 conda-forge 打包 |(默认,2018 年 11 月 13 日,09:50:42)[Clang 9.0.0 (clang-900.0.37)] :: Anaconda custom (64-bit) o​​n darwin

(如果我输入python3,我得到的结果完全一样)

现在,当查看 Atompython 版本时,我得到了 3.6.5 版

<预><代码>>>>导入系统>>>打印(系统版本3.6.5 |由 conda-forge 打包 |(默认,2018 年 4 月 6 日,13:44:09)[GCC 4.2.1 兼容 Apple LLVM 6.1.0 (clang-602.0.53)]

怎么来的?如何让 Atom 获得与终端获得的版本相同的版本?

尝试失败

使用命令 import sysprint(sys.path) 查看 PATH 这是我得到的:

来自原子:

['', '/anaconda3/lib/python36.zip', '/anaconda3/lib/python3.6','/anaconda3/lib/python3.6/lib-dynload', '/anaconda3/lib/python3.6/site-packages','/anaconda3/lib/python3.6/site-packages/aeosa', '/anaconda3/lib/python3.6/site-packages/cycler-0.10.0-py3.6.egg','/anaconda3/lib/python3.6/site-packages/IPython/extensions', '/Users/mymac/.ipython']

从终端:

['', '/Users/mymac/anaconda3/lib/python37.zip','/Users/mymac/anaconda3/lib/python3.7','/Users/mymac/anaconda3/lib/python3.7/lib-dynload','/Users/mymac/anaconda3/lib/python3.7/site-packages','/Users/mymac/anaconda3/lib/python3.7/site-packages/aeosa']

似乎Atom 正在使用pyenv 的Python 版本,给出以下命令和输出:

$ pyenv 版本* 系统(由/Users/mymac/.pyenv/version 设置)3.6.5

根据 pyenv 的 github 页面.我输入了 pyenv virtualenv 3.7.1.然后在输入 $ pyenv versions 时,至少 3.7.1 版本在列表中:

* 系统(由/Users/mymac/.pyenv/version 设置)3.6.53.7.1

但这并没有解决Atom

的问题

然后我访问了 conda 页面 关于管理环境并运行以下命令:

$ conda create --name myenv

它运行没有问题,但问题仍然存在

然后我尝试更具体地运行 $ conda create -n myenv python=3.7.1 但得到:CondaValueError:前缀已经存在:/Users/mymac/anaconda3/envs/myenv

正如@jmh 所指出的,然后我尝试了:$ source activate 3.7.1 并得到以下提示:(3.7.1) user:~ user$

我可以成功地选择正确的 virtualenv.但是在打开 Atom 后问题仍然存在

解决方案

好吧,实际上我不得不更改 jupyter 内核的 .json 文件中的 Path.首先我查看了 jupyter 内核列表:

$ jupyter kernelspec 列表julia-0.6/Users/mymac/Library/Jupyter/kernels/julia-0.6julia-1.0/Users/mymac/Library/Jupyter/kernels/julia-1.0python3/Users/mymac/Library/Jupyter/kernels/python3

然后我cd上面的python路径,我在里面找到文件kernel.json并打开它:

<代码>{argv":["/path/to/python","-m","ipykernel_launcher",-F",{connection_file}"],"display_name": "Python 3",语言":蟒蛇"}

在该文件中,我通过在终端中键入以下内容时得到的 python 路径更改了 /path/to/python 行:

$ which python/用户/mymac/anaconda3/bin/python

重新启动 Atom 终于成功了!

jupyter 的github页面的提示也有很大帮助!>

When I run Python from the terminal and from Atom, different versions of python are called. As a consequence, there are packages that I can call without problems from the terminal but that I cannot call from Atom. Here are the details:

When calling python from the terminal, I get version 3.7.1

$ python
Python 3.7.1 | packaged by conda-forge | (default, Nov 13 2018, 09:50:42) 
[Clang 9.0.0 (clang-900.0.37)] :: Anaconda custom (64-bit) on darwin

(I get exactly the same if I type python3instead)

Now when looking at the python version from Atom i get version 3.6.5 with

>>> import sys
>>> print(sys.version
3.6.5 | packaged by conda-forge | (default, Apr  6 2018, 13:44:09) 
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)]

how come? how can I make Atom get the same version as the version the Terminal is getting?

Failed attempts

Looking at the PATH with the command import sys and then print(sys.path) here is what I get:

From Atom:

['', '/anaconda3/lib/python36.zip', '/anaconda3/lib/python3.6', 
'/anaconda3/lib/python3.6/lib-dynload', '/anaconda3/lib/python3.6/site-packages',
'/anaconda3/lib/python3.6/site-packages/aeosa', '/anaconda3/lib/python3.6/site-packages/cycler-0.10.0-py3.6.egg', 
'/anaconda3/lib/python3.6/site-packages/IPython/extensions', '/Users/mymac/.ipython']

From the Terminal:

['', '/Users/mymac/anaconda3/lib/python37.zip', 
'/Users/mymac/anaconda3/lib/python3.7', 
'/Users/mymac/anaconda3/lib/python3.7/lib-dynload', 
'/Users/mymac/anaconda3/lib/python3.7/site-packages', 
'/Users/mymac/anaconda3/lib/python3.7/site-packages/aeosa']

It seems Atom is using the version of Python of pyenv given the following command and output:

$ pyenv versions
* system (set by /Users/mymac/.pyenv/version)
  3.6.5

according to the github page of pyenv. I entered pyenv virtualenv 3.7.1. Then when entering $ pyenv versions at least the version 3.7.1 was in the list:

* system (set by /Users/mymac/.pyenv/version)
  3.6.5
  3.7.1

But that didn't solve the problem with Atom

I then visited the conda page aboute managing environment and ran the following commands:

$ conda create --name myenv

It ran without problem, but the problem persists

I then tried to run more specifically $ conda create -n myenv python=3.7.1 but got: CondaValueError: prefix already exists: /Users/mymac/anaconda3/envs/myenv

As pointed by @jmh Then I tried: $ source activate 3.7.1 and got the following prompt: (3.7.1) user:~ user$

I could successfully choose the correct the correct virtualenv. But then upon opening Atom the problem persisted

解决方案

Ok, I had actually to change the Path in the .json file of the jupyter kernel. First I checked the list of jupyter kernel:

$ jupyter kernelspec list
julia-0.6    /Users/mymac/Library/Jupyter/kernels/julia-0.6
julia-1.0    /Users/mymac/Library/Jupyter/kernels/julia-1.0
python3      /Users/mymac/Library/Jupyter/kernels/python3

I then cd the above python path and, I found the file kernel.json inside and opened it:

{
 "argv": [
  "/path/to/python",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "Python 3",
 "language": "python"
}

In that file, I then changed the line /path/to/python by the python path I got when typing the following in Terminal:

$ which python
/Users/mymac/anaconda3/bin/python

Relaunched Atom and it finally worked!

The hints of the github page of jupyter helped also a lot!

这篇关于为什么从终端和 Atom 调用时 python 的版本不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆