小编RMP*_*MPR的帖子

Python用win32print打印pdf文件

我正在尝试使用模块从 Python 打印 pdf 文件,win32print但我可以打印成功的唯一方法是文本。

hPrinter = win32print.OpenPrinter("\\\\Server\Printer")
filename = "test.pdf"
try:
    hJob = win32print.StartDocPrinter(hPrinter, 1, ('PrintJobName', None, 'RAW'))
    try:
        win32api.ShellExecute(0, "print", filename, None, ".", 0)
        win32print.StartPagePrinter(hPrinter)
        win32print.WritePrinter(hPrinter, "test")  # Instead of raw text is there a way to print PDF File ?
        win32print.EndPagePrinter(hPrinter)
    finally:
        win32print.EndDocPrinter(hPrinter)
finally:
    win32print.ClosePrinter(hPrinter)

Run Code Online (Sandbox Code Playgroud)

因此,我需要打印“test.pdf”文件而不是打印文本。

我也尝试过,win32api.ShellExecute(0, "print", filename, None, ".", 0)但它不起作用,经过一些测试(例如(getprinter、getdefault、setprinter、setdefaultprinter)之后,它似乎没有连接打印机。所以这样我就无法工作了。

这是我使用的代码!

win32print.SetDefaultPrinter(hPrinter)
win32api.ShellExecute(0, "print", filename, None,  ".",  0)
Run Code Online (Sandbox Code Playgroud)

python windows printing pdf python-3.x

10
推荐指数
3
解决办法
8680
查看次数

Scapy:获取/设置数据包的频率或通道

我一直在尝试使用 Linux 捕获 WIFI 数据包,并查看捕获数据包的频率/频道。我尝试了 Wireshark,但没有运气也没有帮助。虽然使用来自 Wireshark的示例数据包,但我可以看到频率/频道。

所以现在我正在试验 Scapy。我想弄清楚嗅探数据包的频率/频道,但仍然没有运气。有没有办法用 Scapy 做到这一点。

PS 如果有比 Scapy 或 Python 更好的工具,我感谢评论

python scapy wireshark python-3.x

10
推荐指数
1
解决办法
1538
查看次数

Windows上的PySide2

有谁知道我在哪里可以找到PySide2的pip-install?

这是2017年,我似乎无法找到包含PySide2二进制文件的pip安装或site-package.我不想处理下载源代码并自行编译,因为这通常会让人头疼,因为它从来都不是一个平滑的过程.也考虑到其他人很可能已经做到了.如果我在这里说实话,如果我试图自己编译并出现错误,我真的不知道从哪里开始解决它们,我也不想花时间去做.

我发现很难相信当VFX行业的很多应用程序都转向PySide2时,我无法在网上或甚至在PIP中找到它.

我希望有人可以帮助我.谢谢

python windows python-3.x pyside2

9
推荐指数
3
解决办法
5276
查看次数

如何在使用 Http.sys 和 URLPrefix 的同时配置 dotnet core 3 以提供 React SPA?

更改 URLPrefix 后,出现以下错误:

SPA 默认页面中间件无法返回默认页面“/index.html”,因为未找到它,并且没有其他中间件处理该请求。

因此需要一些东西来告诉 dotnet core 关于前缀,但我似乎无法找到正确的设置组合。

非常感谢帮助。

代码如下:

HostBuilder 设置为:

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
    .ConfigureWebHostDefaults(webBuilder =>
    {
        webBuilder.UseHttpSys(options =>
        {
            options.AllowSynchronousIO = false;
            options.Authentication.Schemes = AuthenticationSchemes.None;
            options.Authentication.AllowAnonymous = true;
            options.MaxConnections = null;
            options.MaxRequestBodySize = 30000000;
            options.UrlPrefixes.Add("http://localhost:5005/Product/Site");
        });
        webBuilder.UseStartup<Startup>();
    });
Run Code Online (Sandbox Code Playgroud)

配置服务:

public override void ConfigureServices(IServiceCollection services)
{
  services.AddRazorPages();

  services.AddSpaStaticFiles(configuration =>
  {
    configuration.RootPath = "ClientApp/build";
  });

  services.AddMvc();
  services.AddResponseCompression(opts =>
  {
    opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(
              new[] { "application/octet-stream" });
  });
}
Run Code Online (Sandbox Code Playgroud)

然后配置是:

      app.UseSpaStaticFiles();
      app.UseRouting();
      app.UseEndpoints
      (
        endpoints => …
Run Code Online (Sandbox Code Playgroud)

single-page-application .net-core httpsys

9
推荐指数
1
解决办法
842
查看次数

如何在 Fedora 上安装旧版本的 gcc

我尝试在 Fedora 31 上安装 CUDA 但在最后一步卡住了,因为 CUDA 官方支持 Fedora 29 (gcc 8.2) 而 Fedora 31 附带的版本是 9.2,然后我安装了支持 CUDA 的 Pytorch,不出所料,CUDA 支持是不存在:

>>> import torch
>>> device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
>>> device
device(type='cpu')
Run Code Online (Sandbox Code Playgroud)

然后我尝试在pkgs上搜索 gcc、g++ 和 gfortran ,但陷入了依赖地狱,例如:

sudo dnf install gcc-8.2.1-2.fc29.x86_64.rpm gcc-gfortran-8.2.1-2.fc29.x86_64.rpm gcc-c++-8.2.1-2.fc29.x86_64.rpm -y

Error: 
 Problem 1: conflicting requests
  - nothing provides cpp = 8.2.1-2.fc29 needed by gcc-8.2.1-2.fc29.x86_64
  - nothing provides libgomp = 8.2.1-2.fc29 needed by gcc-8.2.1-2.fc29.x86_64
 Problem 2: conflicting requests
  - nothing provides libgfortran …
Run Code Online (Sandbox Code Playgroud)

linux gcc python-3.x pytorch

7
推荐指数
1
解决办法
4125
查看次数

如何在 linux ubuntu 18.04 python 3.7 上使用 pip 安装 venv

我试图安装venv使用pip,它给了我下面的错误信息:

这是命令:

$ pip install venv

Run Code Online (Sandbox Code Playgroud)

和错误:

Collecting venv
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 353, in run
    wb.build(autobuilding=True)
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 749, in build
    self.requirement_set.prepare_files(self.finder)
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 554, in _prepare_file
    require_hashes
  File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 278, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 465, in find_requirement
    all_candidates = self.find_all_candidates(req.name)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 423, …
Run Code Online (Sandbox Code Playgroud)

python pip virtualenv

6
推荐指数
1
解决办法
1821
查看次数

在回归模型中减少一个变量对输出的影响

目前我正在实施一个高斯回归过程模型,并且在尝试将其应用于我的问题范围时遇到了一些问题。我的问题是我将三个变量作为模型的输入,其中一个值 ( theta) 的影响比其他两个值大得多,alpha1alpha2. 输入和输出具有以下值(为了更好地理解,只有几个值):

# X (theta, alpha1, alpha2)
array([[ 9.07660169,  0.61485493,  1.70396493],
       [ 9.51498486, -5.49212002, -0.68659511],
       [10.45737558, -2.2739529 , -2.03918961],
       [10.46857663, -0.4587848 ,  0.54434441],
       [ 9.10133699,  8.38066374,  0.66538822],
       [ 9.17279647,  0.36327109, -0.30558115],
       [10.36532505,  0.87099676, -7.73775872],
       [10.13681026, -1.64084098, -0.09169159],
       [10.38549264,  1.80633583,  1.3453195 ],
       [ 9.72533357,  0.55861224,  0.74180309])

# y
array([4.93483686, 5.66226844, 7.51133372, 7.54435854, 4.92758927,
       5.0955348 , 7.26606153, 6.86027353, 7.36488184, 6.06864003])
Run Code Online (Sandbox Code Playgroud)

可以看出,thetay 的值显着改变,而alpha1和 的变化在alpha2y 上更为微妙。

我面临的情况是,我正在将模型应用于我的数据,并且在此模型之外,我正在将 Scipy 的最小化应用于模型,将其中一个输入变量固定为此最小化。下面的代码可能会更好地说明:

# …
Run Code Online (Sandbox Code Playgroud)

python machine-learning scipy scikit-learn

6
推荐指数
1
解决办法
212
查看次数

成对扩展 docker swarm 服务

我是 docker swarm 的新手,并且有一个问题,我试图将两个服务成对地扩展。我的环境由以下部分组成:

  • 作业队列(activemq)
  • 返回模型结果的网络服务(tensorflow 服务)
  • 存储结果的缓存(memcached)
  • 一个代理,它是自定义的 Java 代码,编写为胶水代码,从队列中获取,使用 web 服务进行处理并存储在 memcached 中。

我想扩展代理和 tensorflow 网络服务,以便代理只能发送到一个 tensorflow 服务实例,将服务配对在一起。我能够创建代理和 tensorflow Web 服务的副本并使其正常工作,但这是将我的请求循环到每个 tensorflow 容器。

将代理和 tensorflow 网络服务配对在一起以便每个代理只提交给一个 tensorflow 服务我需要考虑什么?

2020 年 3 月 3 日下午 10:02 更新: 看起来我可以使用这里讨论的服务模板:

但是我尝试附加下面的模板,并且无法从连接到同一网络的集群中的另一个容器 ping 容器。而其他容器别名工作。

   networks:
      ml-network:
        aliases:
          - "tensorflowserving{{.Task.Slot}}"
Run Code Online (Sandbox Code Playgroud)

docker-ce 版本 19.03.6

docker docker-swarm

5
推荐指数
0
解决办法
95
查看次数

在 Linux Mint 上安装 pyttsx3

我成功安装了 pyttsx3pip install pyttsx3并编写了以下代码:

import pyttsx3 

def speak(text):
     engine = pyttsx3.init()
     engine.say(text)
     engine.runAndWait()
text = 'hello'
speak(text)
Run Code Online (Sandbox Code Playgroud)

当我运行代码时,出现以下错误:

Traceback (most recent call last):
File "/home/walter197/.local/lib/python3.6/site-packages/pyttsx3/__init__.py", line 20, in init
eng = _activeEngines[driverName]
File "/usr/lib/python3.6/weakref.py", line 137, in __getitem__
o = self.data[key]()
KeyError: None

During handling of the above exception, another exception occurred: 

Traceback (most recent call last):
File "scrap.py", line 104, in <module>
speak(text)
File "scrap.py", line 100, in speak
engine = pyttsx3.init()
File "/home/walter197/.local/lib/python3.6/site-packages/pyttsx3/__init__.py", line 22, in …
Run Code Online (Sandbox Code Playgroud)

python linux python-3.x pyttsx

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

将 Numpy 二维数组转换为字典映射列表

我有一个 Numpy 2D 数组和一个标题列表。Numpy 数组的每一行都是一条要映射到头部列表的记录。最后,我想将每条记录转换为字典(因此有一个字典列表)。例如:

A = [[1, 2, 3], [4, 5, 6]]
headers = ['a', 'b', 'c']
Run Code Online (Sandbox Code Playgroud)

输出:

[{'a' : 1, 'b' : 2, 'c' : 3}, {'a' : 4, 'b' : 5, 'c' : 6}]
Run Code Online (Sandbox Code Playgroud)

在 Python 中实现这一目标的最快方法是什么?我有 10^4 行和 10 个标题,运行它大约需要 0.3 秒。

此时,我有以下代码:

current_samples = A # The samples described above as input, a Numpy array
locations = []
for i, sample in enumerate(current_samples):
    current_location = dict()
    for index, dimension in enumerate(headers):
        current_location[dimension] = sample[index]
    locations.append(current_location)
Run Code Online (Sandbox Code Playgroud)

python numpy

4
推荐指数
1
解决办法
120
查看次数