我正在尝试安装python.或者实际上,现在已经安装和卸载了几次.我正在使用pythonxy与spyder IDE(我习惯使用matlab是我想使用spyder的原因).3.3.2 python甚至不会在我的win8机器上用spyder开始,所以现在我安装了2.7版本.
Spyder现在启动,但在启动时我得到'import sitecustomize'失败了吗?在我的控制台和python中不会执行我输入的任何命令.在错误之后,startupscript继续不做任何事情,我不能再做任何事了.错误告诉我用-v附录启动python,输出如下.
我用谷歌搜索了这个错误,它给了我两个可能的解决方案:我应该编辑python.rb https://github.com/mxcl/homebrew/commit/10ba101c323f98118b427f291e15abc5b3732991 或者我应该将此(在那里的最后一篇文章中的附件)应用到sitecustomize https:/ /code.google.com/p/spyderlib/issues/detail?id=771
应用diff文件没有帮助,正如mata在下面解释的那样,在安装过程中使用.rb文件,因此不适用于我的问题.
所以我的问题是:有人知道如何从经验中修复这个错误吗?
错误:
'import sitecustomize' failed; use -v for traceback
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Run Code Online (Sandbox Code Playgroud)
追溯:
C:\Python27\lib\site-packages\spyderlib\pil_patch.pyc matches C:\Python27\lib\site-packages\spyderlib\pil_patch.py
import spyderlib.pil_patch # precompiled from C:\Python27\lib\site-packages\spyderlib\pil_patch.pyc
Traceback (most recent call last):
File "C:\Python27\lib\site.py", line 498, in execsitecustomize
import sitecustomize
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 174, in <module>
os.environ["SPYDER_AR_STATE"].lower() == "true")
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\monitor.py", line 146, in …Run Code Online (Sandbox Code Playgroud) def sendEmail(to,apNumber,paperType,zipedFile):
sg = sendgrid.SendGridAPIClient(apikey=os.environ.get("API-KEY"))
to_email = mail.Email( "to@email.com")
from_email = mail.Email( "from@email.com" )
subject = 'This is a test email'
content = mail.Content('text/plain', 'Example message.')
message = mail.Mail(from_email, subject, to_email, content)
response = sg.client.mail.send.post(request_body = message.get())
return response
Run Code Online (Sandbox Code Playgroud) 虽然我正在使用的输入数据是随机生成的,但当我使用matplotlib绘制图形时,我只得到了几个不同的不同点!我用过表达式
[[numpy.random.randint(0,20) + numpy.random.random() for i in xrange(100)] for j in xrange(2)]
Run Code Online (Sandbox Code Playgroud)
生成我期望的类似于表面的数据.另外,我没有在输出中添加任何随机性,因为我想确保在我之前合适.
输出也是可疑的,因为它们应该是用等式生成的
z = 112x/2 + 2^.15y + 109
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.
以下是情节的一些看法:

我正在尝试通过"httplib.HTTPSConnection"连接到这个网站"android-review.googlesource.com",这实际上是Gerrit(用于审查代码的工具),Gerrit API提供了JSON格式的审阅数据的接口.我需要收集JSON数据.您可以在此处找到有关Gerrit的更多信息:https://gerritreview.googlesource.com/Documentation/rest-api.html
让我解释一下源代码.有一个名为"GetRequestOrCached"的函数将数据保存在文件中以供缓存使用,另一个函数"MakeRequest"创建与网站的连接并返回响应.但是错误与json.dumps用于请求(req)的部分有关,该请求是字典.
这是错误:
TypeError: <built-in function id> is not JSON serializable
Run Code Online (Sandbox Code Playgroud)
这是代码:
import socket, sys
import httplib
import pyodbc
import json
import types
import datetime
import urllib2
import os
import logging
import re, time
def GetRequestOrCached( url, method, data, filename):
path = os.path.join("json", filename)
if not os.path.exists(path):
data = MakeRequest(url, method, data)
time.sleep(1)
data = data.replace(")]}'", "")
f = open(path, "w")
f.write(data)
f.close()
return open(path).read()
def MakeRequest(url, method, data, port=443):
successful = False
while not successful: …Run Code Online (Sandbox Code Playgroud) 我正在使用PyQt和Python3.
我QTimer没有调用他们被告知连接的功能.isActive()正在返回True,并interval()正在正常工作.下面的代码(单独工作)演示了问题:线程已成功启动,但timer_func()从未调用该函数.大多数代码都是样板PyQT.据我所知,我正在按照文档使用它.它在一个带有事件循环的线程中.有任何想法吗?
import sys
from PyQt5 import QtCore, QtWidgets
class Thread(QtCore.QThread):
def __init__(self):
QtCore.QThread.__init__(self)
def run(self):
thread_func()
def thread_func():
print("Thread works")
timer = QtCore.QTimer()
timer.timeout.connect(timer_func)
timer.start(1000)
print(timer.remainingTime())
print(timer.isActive())
def timer_func():
print("Timer works")
app = QtWidgets.QApplication(sys.argv)
thread_instance = Thread()
thread_instance.start()
thread_instance.exec_()
sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud) 我在edx.com上找到了这个课程的代码.有人能告诉我为什么我必须在for循环中使用余数?它如何影响字典?
def buildCoder(shift):
"""
Returns a dict that can apply a Caesar cipher to a letter.
The cipher is defined by the shift value. Ignores non-letter characters
like punctuation, numbers and spaces.
shift: 0 <= int < 26
returns: dict
"""
dict={}
upper = string.ascii_uppercase
lower = string.ascii_lowercase
for l in range(len(upper)):
dict[upper[l]] = upper[(l+shift)%len(upper)]
for l in range(len(lower)):
dict[lower[l]] = lower[(l+shift)%len(lower)]
return dict
Run Code Online (Sandbox Code Playgroud) python ×5
gerrit ×1
httplib ×1
install ×1
installation ×1
json ×1
numpy ×1
pyqt5 ×1
python-2.7 ×1
python-3.x ×1
qt ×1
sendgrid ×1
spyder ×1