小编Joh*_*hon的帖子

无法从gi.repository导入模块

我无法从gi.repository导入模块.特别是不是Gtk和GObject.

我在Ubuntu 14.04 LTS和Linux Mint 17上重新安装后都遇到了这个错误.

from gi.repository import Gtk, GObject
Run Code Online (Sandbox Code Playgroud)

导致各个模块的"未解决的参考"警告.有趣的是,我的Gtk GUI可以编译并且工作得很好.然而,GObject完全没有功能.

我试图改变导入语句,例如:

from gi.repository.Gtk import*
Run Code Online (Sandbox Code Playgroud)

甚至通过以下硬编码导入路径:

sys.path.append('/usr/lib/python2.7/dist-packages/gi')
Run Code Online (Sandbox Code Playgroud)

到目前为止,这些方法都没有解决这个令人沮丧的错误.

我没有在这个问题上找到任何结论性的帮助或基本信息,无论是在网络上还是在Linux论坛上,或者在stackoverflow上.我不确定这个问题是存在于Python还是Linux方面.

任何人都可以建议如何解决这个问题? 我最终需要提供哪些附加信息.

谢谢!

python gtk import ubuntu gobject

5
推荐指数
1
解决办法
9813
查看次数

使用 multiprocessing.Process 时 Tkinter GUI 冻结

你能向我解释一下,当将工作函数作为单独的进程执行时,如何防止 python GUI 冻结?

我编写了一个 python GUI,单击按钮即可通过多处理模块启动一个进程。我决定使用多处理而不是线程,因为我喜欢选择启动、暂停、恢复和终止进程。

不幸的是,当工作进程运行时,GUI 冻结并变得无响应,因此我无法按“暂停”按钮。

stackoverflow 上多次报告了 GUI 的冻结问题,但似乎没有该问题的单一来源,也没有统一的解决方案。因此我的问题不是重复的。

我目前完全不知道如何解决这个冻结问题。到目前为止,我对解决方案的唯一猜测是使用名为 mtTkinter 的 Tkinter 线程安全包装器,希望它也有助于多处理。但它什么也没做。

也许需要在 GUI 和工作进程之间添加另一层。

欢迎任何建议、提示和解决方案。

最小代码:

import Tkinter as tk
import time
import multiprocessing
import psutil


def test_function():        
    print 'Test process starting.'
    for i in range(11):
        print "Test process running, step: ", i
        time.sleep(1)
    print 'Test process finished.'


   class MainScreen(tk.Tk):

       def __init__(self):
           tk.Tk.__init__(self)
           self.title("CardZilla 0.1")
           self.resizable(0, 0)

           self.s_button = tk.Button(self, text="START", command=self.on_start)
           self.p_button = tk.Button(self, text="PAUSE", state='disabled',  command=self.on_pause)

           self.s_button.pack(side=tk.LEFT)
           self.p_button.pack(side=tk.LEFT)

       def update_all(self): #updates …
Run Code Online (Sandbox Code Playgroud)

python user-interface tkinter freeze multiprocessing

2
推荐指数
1
解决办法
4632
查看次数

Python中的Webdriver - 执行外部JavaScript

我喜欢在python中的webdriver中执行JavaScript.不幸的是,我试图实现它的方式不起作用.我怎样才能正确地做到这一点?

各自的纪录片陈述:(http://selenium-python.readthedocs.org/en/latest/api.html)

driver.execute_script(‘document.title’)
Run Code Online (Sandbox Code Playgroud)

所以我编写了以下python代码:

driver = webdriver.Firefox()    
driver.get("http://google.com")
driver.execute_script("./hello_world.js")    
driver.quit()
Run Code Online (Sandbox Code Playgroud)

在相同的目录中使用相应的hello_world.js:

alert('Hello, World!')
Run Code Online (Sandbox Code Playgroud)

然而,不幸的是它产生了一个Message语法错误:

日志:

Traceback (most recent call last):
  File "/sinonJS_test.py", line 44, in <module>
    sinon_test()
  File "/sinonJS_test.py", line 35, in sinon_test
    driver.execute_script("./hello_world.js")
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",     line 401, in execute_script
{'script': script, 'args':converted_args})['value']
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",     line 173, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 166, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: syntax error
Stacktrace:
    at handleEvaluateEvent (http://google.com:68:11)
Run Code Online (Sandbox Code Playgroud)

解决方案尝试:1)尝试置换hello_world.js文件路径描述,如添加/删除文件后缀,添加/删除绝对文件路径.不工作.

注意:事实上,我在SO上研究了类似问题的几个回答线程,但它们似乎都没有解决我的问题.例如,一些只涉及非常小的脚本通过将JavaScript作为实际python代码中的字符串来解决问题.这不是我的选择,因为我需要执行更大更复杂的JavaScripts(Sinon假定时器).

像这样: Selenium Webdriver:execute_script无法执行自定义方法和外部javascript文件

javascript python selenium

0
推荐指数
1
解决办法
4957
查看次数