提示base.py文件不存在的问题
hchufeng opened this issue · 9 comments
系统为ubuntu16.04,运行pip安装的spyder3.1.3版本,pip源为国内的阿里镜像
在/home/user/.local/lib/python2.7/site-packages/spyder 中,没有发现config,运行python main.py时会报找不到base.py文件和权限不足的问题
解决过程如下:
在/home/user/.local/lib/python2.7/site-packages/spyder下新建 config目录,将/usr/local/lib/python2.7/dist-packages/spyder/config目录下的base.py复制了一份到/home/user/.local/lib/python2.7/site-packages/spyder/config中,再次运行sudo python main.py,运行后的终端显示正常,实际进入spyder中还是无法修改中文。
最终解决方法,将/home/user/.local/lib/python2.7/site-packages/spyder/config中生成的base.py文件复制到/usr/local/lib/python2.7/dist-packages/spyder/config,替代原来的文件,同时将/home/user/.local/lib/python2.7/site-packages/spyder/locale中的zh_CN同样复制过去。
重新启动spyder后,可以正常修改中文。
我对ubuntu不是很熟悉,我们版本一致,在本地测试没有发现问题就直接push了。感谢提供新情况。
谢谢作者的回复,我回复的解决方法只能解决我那台机器的问题,今天特意对照你的main.py代码看了一下我的系统,反馈如下:
n [17]: syspath=sys.path
syspath
Out[18]:
['',
'/usr/local/lib/python2.7/dist-packages/spyder/utils/site',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/local/lib/python2.7/dist-packages/IPython/extensions',
'/home/hu/.ipython']
我个人估计之前出问题的原因可能是在这段代码内,如若不正确,忘作者指正:
sitepath="."
for x in sys.path:
ix=x.find('site-packages')
if( ix>=0 and x[ix:]=='site-packages'):
sitepath=x
break
另外我系统的配置贴给作者看下:
NAME="Ubuntu"
VERSION="16.04.2 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.2 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
python版本:
n [19]: sys.version
Out[19]: '2.7.12 (default, Nov 19 2016, 06:48:10) \n[GCC 5.4.0 20160609]'
platform.platform()
Out[21]: 'Linux-4.4.0-75-generic-x86_64-with-Ubuntu-16.04-xenial'
@kingmo888
感谢作者的努力,经测试,目前的版本已经可以正常安装,暂时没有发现任何错误报出
mac 怎么使用,也存在这个文件找不到的问题。
解决了,找到anacoda 安装路径 bin下的python版本直接执行main.py就可以了,谢谢了。
测试在WIN7方法下:电脑有Anaconda自带python3.6,本机其他地方有3.5版本python,用python main.py 运行失败
Traceback (most recent call last): File "main.py", line 58, in
解决:
直接点击main.py运行即可
for ---------FEDORA-------------
change lib64-----to-----lib
or
set sitepath="/usr/lib/python2.7/site-packages"
//main.py
-- coding: utf-8 --
"""
Created on Fri Mar 10 23:07:29 2017
@author: lizenghai
"""
import os,shutil,sys
import platform
thissys = platform.system()
flag = r'\' if thissys == 'Windows' else '/'
pyver = sys.version_info[0] + sys.version_info[1]/10
def checkpath(path):
try:
tmp = path.split(flag)
if '.' in tmp[-1] and len(tmp)>1:
path = flag.join(tmp[:-1])
except:
pass
if os.path.exists(path):
if os.path.isfile(path)==False:
return path
else:
raise ValueError('文件夹创建失败,存在同名文件。')
else:
os.makedirs(path)
return path
search site-packages folder
sitepath="."
for x in sys.path:
ix1 = x.find('site-packages')
ix2 = x.find('dist-packages')
if( (ix1>=0 and x[ix1:]=='site-packages') or (ix2>=0 and x[ix2:]=='dist-packages') ):
sitepath=x
break
sitepath="/usr/lib/python2.7/site-packages"
creat zh_CN language folder
zh_CN = sitepath + '{0}spyder{1}locale{2}zh_CN{3}LC_MESSAGES'.format(flag,flag,flag,flag)
checkpath(zh_CN)
shutil.copyfile("spyder.mo",zh_CN + r'{0}spyder.mo'.format(flag))
base.py add zh_CN
configpath = sitepath + '{0}spyder{1}config{2}base.py'.format(flag,flag,flag)
print(configpath)
newpath = sitepath + '{0}base.py'.format(flag)
if thissys == 'Windows':
if pyver > 2.7:
newf = open(newpath, 'w', encoding='utf-8')
with open(configpath, 'r',encoding='utf-8') as f:
lines = f.readlines()
else:
import io
newf = io.open(newpath, 'w', encoding='utf-8')
with io.open(configpath, 'r',encoding='utf-8') as f:
lines = f.readlines()
islanguage = 0
for i in range(len(lines)):
line = lines[i]
newf.writelines(line)
if "LANGUAGE_CODES = {'en': u'English'," in line:
#print(line)
islanguage = 1
mystr = " 'zh_CN': u'简体中文',\n" if pyver >2.7 else u" 'zh_CN': u'简体中文',\n"
newf.writelines(mystr)
else:
newf = open(newpath, 'w')
with open(configpath, 'r') as f:
lines = f.readlines()
islanguage = 0
for i in range(len(lines)):
line = lines[i]
newf.writelines(line)
if "LANGUAGE_CODES = {'en': u'English'," in line:
#print(line)
islanguage = 1
mystr = " 'zh_CN': u'简体中文',\n"
newf.writelines(mystr)
newf.close()
rename old base.py
if os.path.exists(sitepath + r'{0}spyder{1}config{2}base_bak.py'.format(flag, flag, flag)):
os.remove(sitepath + r'{0}spyder{1}config{2}base_bak.py'.format(flag, flag, flag))
os.rename(configpath,sitepath + r'{0}spyder{1}config{2}base_bak.py'.format(flag, flag, flag))
remove new base.py
shutil.move(newpath,configpath)
try:
raw_input(u'中文语言包安装完毕,请重启后配置语言选项即可。\n请尽情享用~\n\n 按ENTER键退出。'.encode('gbk'))
except:
input('中文语言包安装完毕,请重启后配置语言选项即可。\n请尽情享用~\n\n 按ENTER键退出。')