简体   繁体   English

用于python 3的National Instruments pyDAQmx

[英]national instruments pyDAQmx for python 3

Python 3.7 Python 3.7

I am writing a Python (3.7) code for National Instruments hardware. 我正在为National Instruments硬件编写Python(3.7)代码。 There is a python library for Python 2.7 . 有一个Python 2.7python库 There are instructions on how to convert the library to be with Python 3. 说明如何将库转换为与Python 3。

  1. I have downloaded PyDAQmx-1.4.1.tar.gz from the project website 我已经从项目网站下载了PyDAQmx-1.4.1.tar.gz
  2. extracted the content of the archive file to a directory 将存档文件的内容提取到目录中
  3. go to that directory in the terminal 转到终端中的该目录
  4. to convert PyDAQmx library from 2 to 3, I run the 2to3 converter in the terminal following instruction . 要将PyDAQmx库从2转换为3,我在终端按照以下说明运行2to3转换器。

C:\\Downloads\\>2to3 --output-dir=PyDAQmx-1.4.1-3 -W -n PyDAQmx-1.4.1 >2to3.log 2>&1

You can inspect the log file for error and warnings. 您可以检查日志文件中的错误和警告。

next,build 接下来,构建

C:\\Downloads\\PyDAQmx-1.4.1-3>py setup.py build >build 2>&1 and install

and install 并安装

C:\\Downloads\\PyDAQmx-1.4.1-3>py setup.py install >install.log 2> &1

this should create an egg file in the Python 3 directory. 这应该在Python 3目录中创建一个egg文件。 And yes indeed there is a file -> PyDAQmx-1.4.1-py3.7.egg 是的,确实有一个文件-> PyDAQmx-1.4.1-py3.7.egg

The first time you will try to import the PyDAQmx library in Python 3 the egg file will be unzipped and you get PyDAQmx subdirectory in the site-packages folder. 首次尝试在Python 3中导入PyDAQmx库时,egg文件将被解压缩,并且您会在site-packages文件夹中找到PyDAQmx子目录。

C:\Python37-32\Lib\PyDAQmx-1.4.1>py
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Inte
l)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import PyDAQmx
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python37-32\Lib\PyDAQmx-1.4.1\PyDAQmx\__init__.py", line 3, in <modul
e>
    import DAQmxConfig
ModuleNotFoundError: No module named 'DAQmxConfig'
>>>

there is DAQmxConfig file in a subdirectory. 子目录中有DAQmxConfig文件。

why didn't it work? 为什么不起作用? and is there a better protocol than what is available on the PyDAQmx website 并且有比PyDAQmx网站上更好的协议

Here is the solution: 解决方法如下:

follow the protocol posted on the webpage 遵循网页上发布的协议

Briefly, 简单地说,

  1. download PyDAQmx-1.4.1.tar.gz from the project website 从项目网站下载PyDAQmx-1.4.1.tar.gz
  2. extract the content of the archive file to a directory 将存档文件的内容提取到目录中
  3. go to that directory in the terminal 转到终端中的该目录
  4. to convert PyDAQmx library from 2 to 3, I run the 2to3 converter in the terminal following instruction . 要将PyDAQmx库从2转换为3,我在终端按照以下说明运行2to3转换器。

C:\\Downloads\\>2to3 --output-dir=PyDAQmx-1.4.1-3 -W -n PyDAQmx-1.4.1 >2to3.log 2>&1

You can inspect the log file for error and warnings. 您可以检查日志文件中的错误和警告。

next, build 接下来,建立

C:\\Downloads\\PyDAQmx-1.4.1-3>py setup.py build >build 2>&1 and install

if you install you indeed get an egg file but there is a corrupted file. 如果安装,确实会得到一个鸡蛋文件,但文件已损坏。

C:\\Downloads\\PyDAQmx-1.4.1-3>py setup.py install >install.log 2> &1

the DAQmxCallBack file is corrupted DAQmxCallBack文件已损坏 在此处输入图片说明

you need to go to \\PyDAQmx-1.4.1-3 folder which you got after the conversion from 2 to 3 and copy the file DAQmxCallBack file from the \\PyDAQmx\\ subdirectory to site-packages subdirectory of Python 3 installation. 您需要转到从2转换为3后获得的\\ PyDAQmx-1.4.1-3文件夹,并将文件DAQmxCallBack文件从\\ PyDAQmx \\子目录复制到Python 3安装的site-packages子目录。

Another way would be to skip the install command and just directly copy PyDAQmx folder from \\PyDAQmx-1.4.1-3 to C:\\Python37-32\\Lib\\site-packages (or wherever you have you python3 installed) 另一种方法是跳过安装命令,直接将PyDAQmx文件夹从\\ PyDAQmx-1.4.1-3复制到C:\\ Python37-32 \\ Lib \\ site-packages(或安装python3的任何位置)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM