我已经使用 PikePDF 和 PDFminer3 构建了一个工作 py 脚本,它将从我的桌面上取下一个 PDF 并从可用的单词中创建一个 txt 文件。
这样做的目的是帮助我的工作团队修改通常无法复制粘贴进行修改的法律文件(因此必须手动输入)。由于我的大多数同事都反对设置 anaconda 和使用 python,我想使用 pyinstaller 将我的脚本转换为 .exe。
当我运行由 pyinstaller 创建的应用程序时,我能够在出现此错误之前完成一些初步输入:
Traceback <most recent call last>:
File 'PDF2TEXT.py', line 35, in <module>
ModuleNotFoundError: No module named 'pikepdf._cpphelpers'
(10688) Failed to execute script PDF2TEXT
Run Code Online (Sandbox Code Playgroud)
在 pyinstaller 的编译过程中,我还收到很多与缺少 anaconda3 dll 文件有关的连续警告:
Warning: lib not found: msmpi.dll dependency of c:\users\anejar1\appdata\local\continuum\anaconda3\Library\bin\mkl_blacs_mspi_ilp64.dll
Run Code Online (Sandbox Code Playgroud)
我已经做了一些挖掘并在其他线程上应用了一些解决方案,但没有成功,包括运行:
pyinstaller --path= [path to pikepdf] --path= [path to pdfminer3] -F PDF2TEXT.py
Run Code Online (Sandbox Code Playgroud)
和
pyinstaller --hidden-import=pikepdf --hidden-import=pdfminer3 -F PDF2TEXT.py
Run Code Online (Sandbox Code Playgroud)
底层代码很短(并且工作正常)并且只从 pikepdf、pdfminer 和 os 导入: …
我正在尝试使用 pip-tools 来管理 venv(如python -m venv .venv)环境。新激活的环境最初只有 pip-tools:
> pip list
Package Version
--------- -------
Click 7.0
pip 19.3.1
pip-tools 4.2.0
six 1.13.0
Run Code Online (Sandbox Code Playgroud)
我创建了一个requirements/main.in文件:
numpy
matplotlib
Run Code Online (Sandbox Code Playgroud)
跑步pip-compile --upgrade --build-isolation --generate-hashes --output-file requirements/main.txt requirements/main.in给了我这个警告:
# WARNING: The following packages were not pinned, but pip requires them to be
# pinned when the requirements file includes hashes. Consider using the --allow-unsafe flag.
# setuptools==41.6.0 # via kiwisolver
The generated requirements file may be rejected by pip …Run Code Online (Sandbox Code Playgroud) Python 包 Flask-HTTPAuth 确实并且可能不会有类型注释(source)。我想创建它们并将它们作为一个包提供在 mypy 上,而不需要分叉项目。我创建了一个flask-httpauth-stubs 包。
我需要做什么才能告诉 mypy 这个包提供了 Flask-HTTPAuth 的存根?
代码.py:
from flask_httpauth import HTTPAuth
def autho(a: HTTPAuth):
return a.get_auth()
Run Code Online (Sandbox Code Playgroud)
然后:
$ pip install flask_httpauth flask_httpauth-stubs
$ mypy code.py
code.py:1: error: Skipping analyzing 'flask_httpauth': found module but no type hints or library stubs
code.py:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)
Run Code Online (Sandbox Code Playgroud)
我还尝试将包重命名为flask_httpauth-stubs以防 CASE 或破折号/下划线很重要。结果一样。
我typing.IO按照文件或类文件对象的类型提示中的建议 进行了尝试?,但它不起作用:
from __future__ import annotations
from tempfile import NamedTemporaryFile
from typing import IO
def example(tmp: IO) -> str:
print(tmp.file)
return tmp.name
print(example(NamedTemporaryFile()))
Run Code Online (Sandbox Code Playgroud)
为此,mypy 告诉我:
test.py:6: error: "IO[Any]" has no attribute "file"; maybe "fileno"?
Run Code Online (Sandbox Code Playgroud)
并且 Python 运行良好。所以代码没问题。
响应库提供请求的模拟。就我而言,它通常看起来像这样:
import responses
@responses.activate
def test_foo():
# Add mocks for service A
responses.add(responses.POST, 'http://service-A/foo', json={'bar': 'baz'}, status=200)
responses.add(responses.POST, 'http://service-A/abc', json={'de': 'fg'}, status=200)
@responses.activate
def test_another_foo():
# Add mocks for service A
responses.add(responses.POST, 'http://service-A/foo', json={'bar': 'baz'}, status=200)
responses.add(responses.POST, 'http://service-A/abc', json={'de': 'fg'}, status=200)
Run Code Online (Sandbox Code Playgroud)
如何避免这种代码重复?
我很想有一个mock_service_a固定装置或类似的东西。
我创建了一个以非常基本的方式使用MySQL数据库的项目.这意味着我只使用SELECT,INSERT,UPDATE和DELETE.没有连接,没有表创建.大多数查询都是SELECT,大多数时候我只选择一行记录.
我也很确定这个项目将始终使用MySQL.
现在我听说过PDO,有些人似乎认为使用它通常是一个好主意.根据php.net"PDO提供[仅]数据访问抽象层".
是否有任何理由为什么一直使用MySQL的项目应该使用PDO?在这样的项目中使用PDO可能是个坏主意的原因吗?
我经常有一些非常长的控制台命令,如:
python /var/www/closure-library/closure/bin/calcdeps.py \
-i myJSFile.js \
-p ../closure-library/closure/goog/ \
-o compiled \
-c /var/www//closure-compiler/build/compiler.jar \
-f "--compilation_level=ADVANCED_OPTIMIZATIONS" \
-f "--define=goog.LOCALE='de'" > myOutputFile.js
Run Code Online (Sandbox Code Playgroud)
我想简单地使用:
closure -i myJSFile.js -o myOutputFile.js
Run Code Online (Sandbox Code Playgroud)
或类似的东西.我怎样才能做到这一点?
c.execute("UPDATE Players SET %s = %d WHERE nick=%s",
(parts[1], int(parts[2]), parts[0]))
Run Code Online (Sandbox Code Playgroud)
给了我错误
TypeError: %d format: a number is required, not str
Run Code Online (Sandbox Code Playgroud)
我知道execute应该只采取%s,但parts[2]应该转换为int,因为它将是一个int(作为字符串输入).
所以,如果我只放了%s,当然它会出现这个错误:
mysql_exceptions.ProgrammingError: (1064,
"You have an error in your SQL syntax; "
"check the manual that corresponds to your MySQL server version "
"for the right syntax to use near "
"''wins' = '450' WHERE nick='xan'' at line 1")
Run Code Online (Sandbox Code Playgroud)
因为wins是整数.这是什么解决方案?
我的代码中有一些部分看起来像这样:
A, B and C extend D
public ArrayList<A> getA() {
ArrayList<A> allElements = new ArrayList<A>();
for (D el : listOfDs) {
if (el instanceof A) {
allElements.add((A) el);
}
}
return allElements;
}
public ArrayList<B> getB() {
ArrayList<B> allElements = new ArrayList<B>();
for (D el : listOfDs) {
if (el instanceof B) {
allElements.add((B) el);
}
}
return allElements;
}
public ArrayList<C> getC() {
ArrayList<C> allElements = new ArrayList<C>();
for (D el : listOfDs) {
if (el instanceof C) …Run Code Online (Sandbox Code Playgroud)