我试图通过遵循python开发人员指南在Ubuntu 12.04上设置CPython的编译版本.即使在安装依赖包lzma和sqlite3之后,构建也会失败,表明找不到依赖模块. 确切错误:
*Python构建完成,但找不到构建这些模块的必要位:_lzma _sqlite3 _tkinter
要查找必要的位,请在detect_modules()中的setup.py中查找模块的名称.*
我无法找到包tkinter.感谢任何帮助.
在win 7上,我可以通过命令行与国际象棋引擎进行通信.Win 7 上与Stockfish的小例子会话:
C:\run\Stockfish>stockfish-x64.exe
Stockfish 2.2.2 JA SSE42 by Tord Romstad, Marco Costalba and Joona Kiiski
quit
C:\run\Stockfish>
Run Code Online (Sandbox Code Playgroud)
第一行由引擎输出,'quit'是我输入的退出引擎(我还可以做其他事情,但这对我来说很清楚).
现在我想从python与该引擎通信:
import subprocess
engine = subprocess.Popen(
'stockfish-x64.exe',
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
)
for line in engine.stdout:
print(line.strip())
engine.stdin.write('quit\n')
Run Code Online (Sandbox Code Playgroud)
我明白了
C:\run\Stockfish>communicate.py
b'Stockfish 2.2.2 JA SSE42 by Tord Romstad, Marco Costalba and Joona Kiiski'
Run Code Online (Sandbox Code Playgroud)
但它没有退出引擎(没有C:\ run\Stockfish>提示),它一直在等待输入.我必须手动关上窗户.似乎没有把我的退出消息(python脚本的最后一行)写入stdin.
换句话说,我可以从stdout读取,但是当我写入stdin时,没有任何事情发生.
我做错了什么,怎么做对了?
编辑:好的,感谢larsmans的帮助我解决了它:
示例Python脚本:
import subprocess, time
engine = subprocess.Popen(
'stockfish-x64.exe',
universal_newlines=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
)
def put(command):
print('\nyou:\n\t'+command)
engine.stdin.write(command+'\n')
def get():
# using the …Run Code Online (Sandbox Code Playgroud) 我正在使用Python 2.7.3.我使用子类multiprocessing.Process对象并行化了一些代码.如果我的子类Process对象中的代码没有错误,那么一切运行正常.但是,如果有在我的子类的过程对象代码中的错误,他们显然会崩溃默默(没有堆栈跟踪打印到父shell)和CPU使用率将下降到零.父代码永远不会崩溃,给人的印象是执行只是挂起.同时,很难追踪代码中的错误,因为没有给出关于错误位置的指示.
我在stackoverflow上找不到任何其他问题来处理同样的问题.
我想子类化的Process对象似乎是静默崩溃的,因为它们无法向父shell发送错误消息,但我想知道我能做些什么,这样我至少可以更高效地调试(以及其他我的代码的用户可以告诉我他们何时遇到问题).
编辑:我的实际代码过于复杂,但在它的错误的子类的处理对象的一个简单的例子是这样的:
from multiprocessing import Process, Queue
class Worker(Process):
def __init__(self, inputQueue, outputQueue):
super(Worker, self).__init__()
self.inputQueue = inputQueue
self.outputQueue = outputQueue
def run(self):
for i in iter(self.inputQueue.get, 'STOP'):
# (code that does stuff)
1 / 0 # Dumb error
# (more code that does stuff)
self.outputQueue.put(result)
Run Code Online (Sandbox Code Playgroud) 是否有pythonic方式并且没有shell命令(即使用子进程模块)来检查目录是否是挂载点?
到目前为止我使用:
import os
import subprocess
def is_mount_point(dir_path):
try:
check_output([
'mountpoint',
path.realpath(dir_name)
])
return True
except CalledProcessError:
return False
Run Code Online (Sandbox Code Playgroud) 我在普通的python shell中,我在尝试导入项目模型时收到此错误:
from results.models import TestResult
Traceback (most recent call last):
File "C:\Program Files (x86)\Wing IDE 3.2\src\debug\tserver\_sandbox.py", line 1, in <module>
# Used internally for debug sandbox under external interpreter
File "C:\Users\audrey_moreau\myProject\results\models.py", line 1, in <module>
from django.db import models
File "c:\Python27\Lib\site-packages\django\db\__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "c:\Python27\Lib\site-packages\django\db\__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "c:\Python27\Lib\site-packages\django\db\utils.py", line 92, in __getitem__
backend = load_backend(db['ENGINE'])
File "c:\Python27\Lib\site-packages\django\db\utils.py", line 54, in load_backend
return import_module('.base', backend_name)
File "c:\Python27\Lib\site-packages\django\utils\importlib.py", line 35, …Run Code Online (Sandbox Code Playgroud) numpy的这种奇怪之处是什么原因all?
>>> import numpy as np
>>> np.all(xrange(10))
False
>>> np.all(i for i in xrange(10))
True
Run Code Online (Sandbox Code Playgroud) 我想制作一个Python程序,它将运行二分法来确定以下的根:
f(x) = -26 + 85x - 91x2 +44x3 -8x4 + x5
Run Code Online (Sandbox Code Playgroud)
二分法是用于估计多项式f(x)的根的数值方法.
我可以使用任何可用的伪代码,算法或库来告诉我答案吗?
出于随机键盘攻击,我最终注意到在SciPy被调用中存在一个变量i,该变量被赋值给字符串'6'.(在其他机器上可能有所不同吗?)
我尝试使用内置帮助功能,但没有分配任何内容,scipy.i因为它只引用一个字符串.
我还搜索了文档和谷歌,但没有出现.
它可能与版本控制或类似的东西有关吗?顺便说一句,我在Windows 7上使用Enthought Python(均为64位).
这远非一个关键问题,我只是好奇它!
我有list1和list2.list2是一组必须从中删除的单词,list1例如:
list1=['paste', 'text', 'text', 'here', 'here', 'here', 'my', 'i', 'i', 'me', 'me']
list2=["i","me"]
Run Code Online (Sandbox Code Playgroud)
期望的输出:
list3=['paste', 'text', 'text', 'here', 'here', 'here', 'my']
Run Code Online (Sandbox Code Playgroud)
我尝试过使用'for'的不同版本但到目前为止没有结果.
任何想法,将不胜感激!
据我所知,pandas数据帧类型具有测试其值的逻辑的能力.
这是代码:
import pandas as pd
data = pd.DataFrame(columns=['a', 'b', 'c'])
data = data.append({'a': 'I have data', 'b': 'no more complexe', 'c': 024204}, ignore_index=True)
data = data.append({'a': 'audoausd', 'b': '2048rafaf', 'c': 29313}, ignore_index=True)
data = data.append({'a': 'koplak ente gan', 'b': 'ente g bisa koplak', 'c': 29313}, ignore_index=True)
Run Code Online (Sandbox Code Playgroud)
现在我们有以下数据帧:
a b c
0 I have data no more complexe 10372
1 audoausd 2048rafaf 29313
2 koplak ente gan ente g bisa koplak 29313
Run Code Online (Sandbox Code Playgroud)
测试列c的逻辑值并将其保存到变量中
c = data.c > 20000
Run Code Online (Sandbox Code Playgroud)
将c设置为以下值
0 …Run Code Online (Sandbox Code Playgroud) python ×10
python-2.7 ×4
python-3.x ×2
algorithm ×1
bisection ×1
chess ×1
django ×1
importerror ×1
list ×1
numpy ×1
pandas ×1
process ×1
python-3.3 ×1
scipy ×1