setup.pyis used by python to createsetuptoolspakcage.- As per
setup.pyand project settings: | Module |crono_exts.timetagger4vector| | Python Installation folder invcxproj|C:\Dev\Python311| | Python folder on the Windows Path |C:\Dev\Python311| - Extension project can be opened from Visual Studio using file
timetagger4ext.vcxproj.
Current structure
└───timetagger4ext
├───include
├───lib # External libraries (driver)
├───src
│ └───crono_exts # The package source code
└───tools # Has project files, package setup files
- Just make sure that the following packages are installed
<path-to-python-installation-folder>/pip install numpy setuptools wheel
- You would need Visual Studio 2022 (not VS Code), you would need to enable C++ and python development in the Installer.
- To configure it for your environment you would not to set the paths for your install , mentioned in the following document: Write C++ extensions for Python - Visual Studio (Windows) | Microsoft Learn.
cd to python_ext\timetagger4ext\tools and run:
python setup.py bdist_wheel sdist
It will build both the package binaries and source distribution. Output:
- In directory:
python_ext\timetagger4ext\tools\dist - Wheel package:
crono_exts-0.1-cp311-cp311-win_amd64.whl. - Source:
crono_exts-0.1.tar.gz
cd to python_ext\timetagger4ext\tools\dist, run:
pip install crono_exts-0.1-cp311-cp311-win_amd64.whl
You should find:
Successfully installed crono-exts-0.1
- Install the package and make sure that the driver dll is installed on the system folder.
- Ensure that the extension APIs are exported, and use them in a sample python app.
- Ensure all source is added to the source package.
- Fill
clasifiersinsetup.py. - Try the package on
test.pypi, could be usingtwinetwine check dist/* twine upload dist/* -r testpypi - Support Linux.
- Sample application that uses the extension.
- Uses
crono_exts.timetagger4vectorextension.
cd TimeTagger4ReadOut\src python TimeTagger4ReadOut\src
- Check prerequisites of the extension.
- Create "Python Application" project from Visual Studio.
- If not created, then create an environment from python installation: Right click
TimeTagger4ReadOut -> Python EnvironmentsthenAdd Environmentthen select the underlying environment fromBase interpreter, assuming calledenv1. - Install
numpy: Right clickTimeTagger4ReadOut -> Python Environments -> env1thenManage Python Packages..., then enternumpyand install it. - Install our extension: Right click
TimeTagger4ReadOut -> Python Environments -> env1thenOpen Interactive Window, then:pip install <path-to-whl>
Here are trials with the results, just to avoid in future any one has problems, last one works successfully:
Installing numpy on Visual Studio bundled python:
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64>.\scripts\pip install numpy
This installed it on:
C:\Users\basse\AppData\Roaming\Python\Python39\site-packages
Conclusion
- A bit annoying setting the paths, and is an old version, trying with the latest python versions.
- Installing latest python: 3.12.
- When setting it as an environment in Visual Studio, a warning that this "This python version is not supported by Visual Studio".
- No problem with python immediately previous version, it's supported.
Conclusion
- Not supported by MSVS.
- Installing python version 3.11.9, asking installer to set it in the environment variables.
- Select it as an environment in Visual Studio Project: Solution Explorer -> TimeTagger4ReadOut -> Python Environments -> Add Environment. Select it from "Base interpreter".
- Install
numpyfrom the project environment.- Right click 'env (Ptyhon 3.11(64-bit))' in the Solution Explorer
- Click "Manage Python Packages"
- Enter "numpy", as it to install it.
- Installing numpy on the python environment (C:\Dev\Python311) externally somehow doesn't avail it for the project, the above way works well.
- Update link and include paths in the project to
C:\Dev\Python311. - Build all succeeds.
- When running,
import numpy as npis OK, but: line:Caused a run-time errorimport timetagger4vector as tt4vDLL load failed while importing timetagger4vector: The specified module could not be found.- I copied
xtdc4_driver_64.dll&timetagger4vector.pydto the .py folder (F:\Work\crono-all\timetagger4python\TimeTagger4ReadOut) and it worked.
- I copied
Conclusion
- Used successfully.