Copying a built framework into Python package with package_data - python

I'm trying to improve the way that PyBluez installs on macOS. Here is what the setup.py code looks like today, before my changes.
In short, on macOS an extra package called lightblue is installed, and this depends on a framework called LightAquaBlue.framework. Today, it invokes xcodebuild to build the framework and install it to /Library/Frameworks, but I want to change it to embed the framework within the Python package.
Here's what I've done:
packages.append('lightblue')
package_dir['lightblue'] = 'osx'
install_requires += ['pyobjc-core>=3.1', 'pyobjc-framework-Cocoa>=3.1']
# Add the LightAquaBlue framework to the package data as an 'eager resource'
# so that we can extract the whole framework at runtime
package_data['lightblue'] = [ 'LightAquaBlue.framework' ]
eager_resources.append('LightAquaBlue.framework')
# FIXME: This is inelegant, how can we cover the cases?
if 'install' in sys.argv or 'bdist' in sys.argv or 'bdist_egg' in sys.argv:
# Build the framework into osx/
import subprocess
subprocess.check_call([
'xcodebuild', 'install',
'-project', 'osx/LightAquaBlue/LightAquaBlue.xcodeproj',
'-scheme', 'LightAquaBlue',
'DSTROOT=' + os.path.join(os.getcwd(), 'osx'),
'INSTALL_PATH=/',
'DEPLOYMENT_LOCATION=YES',
])
This builds the LightAquaBlue.framework inside osx/ (which is the lightblue package's directory) and then passes it to setuptools as package_data. However, when I run pip install --upgrade -v ./pybluez/, the LightAquaBlue.framework is not copied:
creating build/lib/lightblue
copying osx/_bluetoothsockets.py -> build/lib/lightblue
copying osx/_LightAquaBlue.py -> build/lib/lightblue
copying osx/_obexcommon.py -> build/lib/lightblue
copying osx/_IOBluetoothUI.py -> build/lib/lightblue
copying osx/__init__.py -> build/lib/lightblue
copying osx/_IOBluetooth.py -> build/lib/lightblue
copying osx/_obex.py -> build/lib/lightblue
copying osx/_lightblue.py -> build/lib/lightblue
copying osx/obex.py -> build/lib/lightblue
copying osx/_macutil.py -> build/lib/lightblue
copying osx/_lightbluecommon.py -> build/lib/lightblue
If I have setup.py create a dummy file inside osx/, and add it to package_data, it does get copied. This suggests to me there's no confusion over paths.
If I add os.system('ls osx/'), it also shows me that LightAquaBlue.framework is present in the same place as my dummy file.
LightAquaBlue
--> LightAquaBlue.framework
DUMMY_FILE_THAT_WORKS
_IOBluetooth.py
_IOBluetoothUI.py
_LightAquaBlue.py
__init__.py
_bluetoothsockets.py
_lightblue.py
_lightbluecommon.py
_macutil.py
_obex.py
_obexcommon.py
obex.py
Why isn't the framework correctly copied in?

It looks like setuptools' documentation contradicts the implementation and actually you cannot specify a directory to include in package_data.
It's not very elegant, but I used:
# We can't seem to list a directory as package_data, so we will
# recursively add all all files we find
package_data['lightblue'] = []
for path, _, files in os.walk('osx/LightAquaBlue.framework'):
for f in files:
include = os.path.join(path, f)[4:] # trim off osx/
package_data['lightblue'].append(include)

Related

Installing matlab engine to call matlab function from python - python 3.7 is not supported causing import failure

I've done what every guide I have found does. I am in my anaconda enviroment and I have went to the directory where the setup.py is. I install it, then launch python, then try to import it and it says 3.7 is not supported even though it is in the supported list, and I am running 3.7:
(opt) vogtster#Vogtsters-Mini python % python setup.py build --build-base=$(mktemp -d) install --user
/Users/vogtster/opt/anaconda3/envs/opt/lib/python3.7/site-packages/setuptools/dist.py:534: UserWarning: The version specified ('R2022a') is an invalid version, this may not work as expected with newer versions of setuptools, pip, and PyPI. Please see PEP 440 for more details.
"details." % version
running build
running build_py
creating /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib
creating /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib/matlab
copying dist/matlab/__init__.py -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib/matlab
creating /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib/matlab/engine
copying dist/matlab/engine/fevalfuture.py -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib/matlab/engine
copying dist/matlab/engine/matlabengine.py -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib/matlab/engine
copying dist/matlab/engine/basefuture.py -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib/matlab/engine
copying dist/matlab/engine/__init__.py -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib/matlab/engine
copying dist/matlab/engine/matlabfuture.py -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib/matlab/engine
copying dist/matlab/engine/futureresult.py -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib/matlab/engine
copying dist/matlab/engine/enginehelper.py -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib/matlab/engine
copying dist/matlab/engine/engineerror.py -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib/matlab/engine
copying dist/matlab/engine/enginesession.py -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib/matlab/engine
running install
/Users/vogtster/opt/anaconda3/envs/opt/lib/python3.7/site-packages/setuptools/command/install.py:37: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
setuptools.SetuptoolsDeprecationWarning,
/Users/vogtster/opt/anaconda3/envs/opt/lib/python3.7/site-packages/setuptools/command/easy_install.py:147: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.
EasyInstallDeprecationWarning,
/Users/vogtster/opt/anaconda3/envs/opt/lib/python3.7/site-packages/pkg_resources/__init__.py:125: PkgResourcesDeprecationWarning: R2022a is an invalid version and will not be supported in a future release
PkgResourcesDeprecationWarning,
running bdist_egg
running egg_info
writing dist/matlabengineforpython.egg-info/PKG-INFO
writing dependency_links to dist/matlabengineforpython.egg-info/dependency_links.txt
writing top-level names to dist/matlabengineforpython.egg-info/top_level.txt
/Users/vogtster/opt/anaconda3/envs/opt/lib/python3.7/site-packages/setuptools/command/egg_info.py:627: SetuptoolsDeprecationWarning: Custom 'build_py' does not implement 'get_data_files_without_manifest'.
Please extend command classes from setuptools instead of distutils.
SetuptoolsDeprecationWarning
reading manifest file 'dist/matlabengineforpython.egg-info/SOURCES.txt'
writing manifest file 'dist/matlabengineforpython.egg-info/SOURCES.txt'
installing library code to /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg
running install_lib
creating /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64
creating /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg
creating /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/matlab
copying /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib/matlab/__init__.py -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/matlab
creating /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/matlab/engine
copying /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib/matlab/engine/fevalfuture.py -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/matlab/engine
copying /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib/matlab/engine/matlabengine.py -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/matlab/engine
copying /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib/matlab/engine/basefuture.py -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/matlab/engine
copying /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib/matlab/engine/__init__.py -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/matlab/engine
copying /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib/matlab/engine/matlabfuture.py -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/matlab/engine
copying /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib/matlab/engine/_arch.txt -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/matlab/engine
copying /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib/matlab/engine/futureresult.py -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/matlab/engine
copying /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib/matlab/engine/enginehelper.py -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/matlab/engine
copying /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib/matlab/engine/engineerror.py -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/matlab/engine
copying /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/lib/matlab/engine/enginesession.py -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/matlab/engine
byte-compiling /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/matlab/__init__.py to __init__.cpython-37.pyc
byte-compiling /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/matlab/engine/fevalfuture.py to fevalfuture.cpython-37.pyc
byte-compiling /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/matlab/engine/matlabengine.py to matlabengine.cpython-37.pyc
byte-compiling /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/matlab/engine/basefuture.py to basefuture.cpython-37.pyc
byte-compiling /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/matlab/engine/__init__.py to __init__.cpython-37.pyc
byte-compiling /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/matlab/engine/matlabfuture.py to matlabfuture.cpython-37.pyc
byte-compiling /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/matlab/engine/futureresult.py to futureresult.cpython-37.pyc
byte-compiling /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/matlab/engine/enginehelper.py to enginehelper.cpython-37.pyc
byte-compiling /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/matlab/engine/engineerror.py to engineerror.cpython-37.pyc
byte-compiling /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/matlab/engine/enginesession.py to enginesession.cpython-37.pyc
creating /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying dist/matlabengineforpython.egg-info/PKG-INFO -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying dist/matlabengineforpython.egg-info/SOURCES.txt -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying dist/matlabengineforpython.egg-info/dependency_links.txt -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying dist/matlabengineforpython.egg-info/top_level.txt -> /var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
matlab.__pycache__.__init__.cpython-37: module references __file__
matlab.__pycache__.__init__.cpython-37: module references __path__
matlab.engine.__pycache__.__init__.cpython-37: module references __file__
creating 'dist/matlabengineforpython-R2022a-py3.7.egg' and adding '/var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg' to it
removing '/var/folders/2t/1hqm8qtd78xb9grhqz2023_w0000gn/T/tmp.CcDlA6kb/bdist.macosx-10.9-x86_64/egg' (and everything under it)
Processing matlabengineforpython-R2022a-py3.7.egg
removing '/Users/vogtster/.local/lib/python3.7/site-packages/matlabengineforpython-R2022a-py3.7.egg' (and everything under it)
creating /Users/vogtster/.local/lib/python3.7/site-packages/matlabengineforpython-R2022a-py3.7.egg
Extracting matlabengineforpython-R2022a-py3.7.egg to /Users/vogtster/.local/lib/python3.7/site-packages
matlabengineforpython R2022a is already the active version in easy-install.pth
Installed /Users/vogtster/.local/lib/python3.7/site-packages/matlabengineforpython-R2022a-py3.7.egg
Processing dependencies for matlabengineforpython===R2022a
Finished processing dependencies for matlabengineforpython===R2022a
(opt) vogtster#Vogtsters-Mini python % python
Python 3.7.13 (default, Mar 28 2022, 07:24:34)
[Clang 12.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matlab.engine
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/vogtster/.local/lib/python3.7/site-packages/matlabengineforpython-R2022a-py3.7.egg/matlab/__init__.py", line 200, in <module>
success = get_dirs_from_arch_file_without_import()
File "/Users/vogtster/.local/lib/python3.7/site-packages/matlabengineforpython-R2022a-py3.7.egg/matlab/__init__.py", line 159, in get_dirs_from_arch_file_without_import
_PYTHONVERSION = get_python_version()
File "/Users/vogtster/.local/lib/python3.7/site-packages/matlabengineforpython-R2022a-py3.7.egg/matlab/__init__.py", line 150, in get_python_version
raise EnvironmentError("Python %s is not supported." % _version)
OSError: Python 3_7 is not supported.
>>>
This is the directory I am in when I call the python setup.py install - is this wrong somehow?
/Users/vogtster/Desktop/MATLAB_R2022a.app/extern/engines/python
File "/Users/vogtster/.local/lib/python3.7/site-packages/matlabengineforpython-R2022a-py3.7.egg/matlab/__init__.py", line 150, in get_python_version
It was looking locally for some reason. I deleted this, downgraded to R2021a and not everything works great.

MATLAB Engine API for Python. Error: MATLAB Engine for Python supports Python version

I'm working on my Master's Thesis. My director uses MATLAB, I use Python. So I need to run his MATLAB scripts on Python. There are many questions out there on this topic.
I tried to install Install MATLAB Engine API for Python (https://es.mathworks.com/help/matlab/matlab_external/install-the-matlab-engine-for-python.html). I came across the following problem:
Error: MATLAB Engine for Python supports Python version 2.7, 3.7, 3.8, and 3.9, but your version of Python is 3.10
Which alternatives do I have?
Another doubt I have: I checked my Python version by
python3 --version
and I get as an output: Python 3.9.7. I don't understand the Error then.
For the record, I'm using Ubuntu and Anaconda.
At the end, I get it working. Here's how:
HOW TO INSTALL MATLAB Engine API for Python.
Short Answer:
cd "matlabroot"\extern\engines\python
sudo \path_to_compatible_Python_version setup.py install
Long Answer:
You need Matlab correctly installed (I will skip this step)
Find the matlabroot (where is your Matlab installed). In Matlab's Command Window, type:
matlabroot
the ans is 'your matlabroot'. In my case, it is: '/usr/local/MATLAB/R2022a'
Open a terminal and type:
cd "matlabroot/extern/engines/python"
Just remember to change 'matlabroot' with 'your matlabroot' (i.e. output in step 2)
Run setup.py. 2 ways:
4.1 You can try: (it didn't work for me, but it is recommended in Install MATLAB Engine API for Python
python setup.py install
4.2 If you get the error:
error: could not create 'build': Permission denied
try to run it with sudo:
sudo python3 setup.py install
(I changed 'python' by 'python3')
Then you may get the version Error. It's something like:
EnvironmentError('MATLAB Engine for Python supports Python version')
OSError: MATLAB Engine for Python supports Python version [···], but your version of Python is [···].
You can check your Python with python -V
There is a chance you have more than one version of Python installed. You must make sure to use the direct path to the python.exe you want rather than the shortcut python3.
Let's do it. You can type into the terminal
which python.
This give use where python3 is located. (e.g. I get /home/user_name/anaconda3/bin/python3)
Go to the directory /home/user_name/anaconda3/bin (we omited python3 because this refers to a Symlink, not a directory)
There we should see (type ls) a symlink (word in Cyan) called python3
we can find the original file of a symbolic link by:
readlink -f python3
High are the chance, it is in the same directory (if not, go there). We need to search for a python version compatible with your matlab version. You can know that by the OSError or in Versions of Python Compatible with MATLAB Products by Releas
Type ls again in the same directory and search for a python compatible with your Matlab (green word). In my case, I found python3.9 and it works with my Matlab version.
Now, you have a compatible version of Python located, repeat step 3. Run setup.py but this time change python3 with the new python direction we just have found. In my case this look as follows:
sudo /home/user_name/anaconda3/bin/python3.9 setup.py install
All this worked for me. Good luck!
CU
To install matlab.engine on Ubuntu/Debian for python 3.9 and configure it with a conda environment, use the following procedure:
Activate your conda environment on the commandline
$ conda activate <your_amazing_conda_env>
Then, install matlab kernel
$ pip install matlab-kernel
Change to the matlab installation directory
$ cd /usr/local/MATLAB/R2022a/extern/engines/python
Install matlab.engine by directly pointing to location where your anaconda environment lives. For e.g.
$ sudo "/home/mario/anaconda3/envs/chamois/bin/python" setup.py install
Note that you need admin privileges in the last step.
If your installation is successful, you will get stack traces something like the following:
reading manifest file 'dist/matlabengineforpython.egg-info/SOURCES.txt'
writing manifest file 'dist/matlabengineforpython.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/matlab
copying build/lib/matlab/__init__.py -> build/bdist.linux-x86_64/egg/matlab
creating build/bdist.linux-x86_64/egg/matlab/engine
copying build/lib/matlab/engine/engineerror.py -> build/bdist.linux-x86_64/egg/matlab/engine
copying build/lib/matlab/engine/basefuture.py -> build/bdist.linux-x86_64/egg/matlab/engine
copying build/lib/matlab/engine/futureresult.py -> build/bdist.linux-x86_64/egg/matlab/engine
copying build/lib/matlab/engine/__init__.py -> build/bdist.linux-x86_64/egg/matlab/engine
copying build/lib/matlab/engine/_arch.txt -> build/bdist.linux-x86_64/egg/matlab/engine
copying build/lib/matlab/engine/enginehelper.py -> build/bdist.linux-x86_64/egg/matlab/engine
copying build/lib/matlab/engine/matlabfuture.py -> build/bdist.linux-x86_64/egg/matlab/engine
copying build/lib/matlab/engine/enginesession.py -> build/bdist.linux-x86_64/egg/matlab/engine
copying build/lib/matlab/engine/fevalfuture.py -> build/bdist.linux-x86_64/egg/matlab/engine
copying build/lib/matlab/engine/matlabengine.py -> build/bdist.linux-x86_64/egg/matlab/engine
byte-compiling build/bdist.linux-x86_64/egg/matlab/__init__.py to __init__.cpython-39.pyc
byte-compiling build/bdist.linux-x86_64/egg/matlab/engine/engineerror.py to engineerror.cpython-39.pyc
byte-compiling build/bdist.linux-x86_64/egg/matlab/engine/basefuture.py to basefuture.cpython-39.pyc
byte-compiling build/bdist.linux-x86_64/egg/matlab/engine/futureresult.py to futureresult.cpython-39.pyc
byte-compiling build/bdist.linux-x86_64/egg/matlab/engine/__init__.py to __init__.cpython-39.pyc
byte-compiling build/bdist.linux-x86_64/egg/matlab/engine/enginehelper.py to enginehelper.cpython-39.pyc
byte-compiling build/bdist.linux-x86_64/egg/matlab/engine/matlabfuture.py to matlabfuture.cpython-39.pyc
byte-compiling build/bdist.linux-x86_64/egg/matlab/engine/enginesession.py to enginesession.cpython-39.pyc
byte-compiling build/bdist.linux-x86_64/egg/matlab/engine/fevalfuture.py to fevalfuture.cpython-39.pyc
byte-compiling build/bdist.linux-x86_64/egg/matlab/engine/matlabengine.py to matlabengine.cpython-39.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying dist/matlabengineforpython.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying dist/matlabengineforpython.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying dist/matlabengineforpython.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying dist/matlabengineforpython.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
matlab.__pycache__.__init__.cpython-39: module references __file__
matlab.__pycache__.__init__.cpython-39: module references __path__
matlab.engine.__pycache__.__init__.cpython-39: module references __file__
creating 'dist/matlabengineforpython-R2022a-py3.9.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing matlabengineforpython-R2022a-py3.9.egg
removing '/home/mario/anaconda3/envs/chamois/lib/python3.9/site-packages/matlabengineforpython-R2022a-py3.9.egg' (and everything under it)
creating /home/mario/anaconda3/envs/chamois/lib/python3.9/site-packages/matlabengineforpython-R2022a-py3.9.egg
Extracting matlabengineforpython-R2022a-py3.9.egg to /home/mario/anaconda3/envs/chamois/lib/python3.9/site-packages
matlabengineforpython R2022a is already the active version in easy-install.pth
Installed /home/mario/anaconda3/envs/chamois/lib/python3.9/site-packages/matlabengineforpython-R2022a-py3.9.egg
Processing dependencies for matlabengineforpython===R2022a
Finished processing dependencies for matlabengineforpython===R2022a
After that, you can test the working of the installation by importing matlab.engine in a python terminal.
In [1]: import matlab.engine
In [2]: matlab.engine.__spec__
Out[2]: ModuleSpec(name='matlab.engine', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7fe58c4514f0>, origin='/home/mario/anaconda3/envs/chamois/lib/python3.9/site-packages/matlabengineforpython-R2022a-py3.9.egg/matlab/engine/__init__.py', submodule_search_locations=['/home/mario/anaconda3/envs/chamois/lib/python3.9/site-packages/matlabengineforpython-R2022a-py3.9.egg/matlab/engine'])
In [3]: matlab.engine.__name__
Out[3]: 'matlab.engine'
In [4]: matlab.engine.__path__
Out[4]: ['/home/mario/anaconda3/envs/chamois/lib/python3.9/site-packages/matlabengineforpython-R2022a-py3.9.egg/matlab/engine']

cx Freeze "[Error 3] The system cannot find the path specified"

Windows 7 x64, Python 2.7 (Anaconda distribution), cx_Freeze 5.0.
I've made a GUI application using PyQt4 and am trying to freeze the python script but get the following error:
Copying data from package PyQt4...
copying C:\Users\Ben\Anaconda2\lib\site-packages\PyQt4\QtCore.pyd -> build\exe.win-amd64-2.7\PyQt4\QtCore.pyd
copying C:\Users\Ben\Anaconda2\Library\bin\QtCore4.dll -> build\exe.win-amd64-2.7\QtCore4.dll
copying C:\Users\Ben\Anaconda2\Library\bin\MSVCP90.dll -> build\exe.win-amd64-2.7\MSVCP90.dll
copying C:\Users\Ben\Anaconda2\lib\site-packages\PyQt4\QtGui.pyd -> build\exe.win-amd64-2.7\PyQt4\QtGui.pyd
copying C:\Users\Ben\Anaconda2\Library\bin\QtGui4.dll -> build\exe.win-amd64-2.7\QtGui4.dll
copying C:\Users\Ben\Anaconda2\Library\bin\libpng16.dll -> build\exe.win-amd64-2.7\libpng16.dll
copying C:\Users\Ben\Anaconda2\lib\site-packages\PyQt4\QtSvg.pyd -> build\exe.win-amd64-2.7\PyQt4\QtSvg.pyd
copying C:\Users\Ben\Anaconda2\Library\bin\QtSvg4.dll -> build\exe.win-amd64-2.7\QtSvg4.dll
Copying data from package _dummy_thread...
Copying data from package _markerlib...
error: [Error 3] The system cannot find the path specified: 'C:\\Users\\Ben\\Anaconda2\\lib\\site-packages\\setuptools-19.2-py2.7.egg\\_markerlib/*.*'
My cx freeze setup file is:
import sys
from cx_Freeze import setup, Executable
#import matplotlib
base = None
if sys.platform == "win32":
base = "Win32GUI"
build_options = {"packages":["matplotlib", "xlrd", "xlwt"],
"include_files":["Mefisto_logo.jpg", "LOGO H2020 RIA.png", "logo_h2020_transparent.png",
"logo_minouw.png", "logo-csic.png", "logo-icm.png", "logo-icm-ca-csic.png"] }
executables = [Executable("mefisto_main_10.py", base=base, icon="Mefisto_logo.ico")]
# Note for some reason the icon must be .ico - cx freeze will not work with either jpg or png
setup(name = "Mefisto",
version = "4.01",
description = "Mediterranean fisheries simulation tool",
options = {"build_exe": build_options},
executables = executables
)
Thanks for any help offered.
Well I found a solution to my problem based on comments in this post.
I changed the extension of
setuptools-19.2-py2.7.egg
to zip and unzipped it. The cx_freeze script then worked and created the build. (I have another problem however - the exe created doesn't do anything when clicked - but that's my next investigation...)

I try to build a universal wheel, but it rolls away

I run:
python3 setup.py bdist_wheel --universal
It says it's making all sorts of stuff, but then the resulting directory (build/bdist.macosx-10.10-x86_64) is empty. Where did my wheel roll away to?t
Edit
I now see that I'm trying to look at the temp output. When I specify -d, sure enough, there's a wheel in the designated location. Does -d have a default? Has my wheel been parked under my nose all along?
running bdist_wheel
running build
running build_py
running egg_info
writing dependency_links to rosapi_launcher.egg-info/dependency_links.txt
writing top-level names to rosapi_launcher.egg-info/top_level.txt
writing rosapi_launcher.egg-info/PKG-INFO
writing requirements to rosapi_launcher.egg-info/requires.txt
reading manifest file 'rosapi_launcher.egg-info/SOURCES.txt'
writing manifest file 'rosapi_launcher.egg-info/SOURCES.txt'
installing to build/bdist.macosx-10.10-x86_64/wheel
running install
running install_lib
creating build/bdist.macosx-10.10-x86_64/wheel
creating build/bdist.macosx-10.10-x86_64/wheel/launcher
copying build/lib/launcher/__init__.py -> build/bdist.macosx-10.10-x86_64/wheel/launcher
copying build/lib/launcher/containers.py -> build/bdist.macosx-10.10-x86_64/wheel/launcher
copying build/lib/launcher/launcher.py -> build/bdist.macosx-10.10-x86_64/wheel/launcher
copying build/lib/launcher/prop_file.py -> build/bdist.macosx-10.10-x86_64/wheel/launcher
copying build/lib/launcher/properties.py -> build/bdist.macosx-10.10-x86_64/wheel/launcher
copying build/lib/launcher/snapshots.py -> build/bdist.macosx-10.10-x86_64/wheel/launcher
copying build/lib/launcher/utils.py -> build/bdist.macosx-10.10-x86_64/wheel/launcher
running install_egg_info
Copying rosapi_launcher.egg-info to build/bdist.macosx-10.10-x86_64/wheel/rosapi_launcher-0.0.1-py3.4.egg-info
running install_scripts
creating build/bdist.macosx-10.10-x86_64/wheel/rosapi_launcher-0.0.1.dist-info/WHEEL
My setup.py is:
from setuptools import setup
import io
import os
import launcher
here = os.path.abspath(os.path.dirname(__file__))
# noinspection PyPackageRequirements
def read(*filenames, **kwargs):
encoding = kwargs.get('encoding', 'utf-8')
sep = kwargs.get('sep', '\n')
buf = []
for filename in filenames:
with io.open(filename, encoding=encoding) as f:
buf.append(f.read())
return sep.join(buf)
long_description = read('README.txt', 'CHANGES.txt')
setup(
name='rosapi-launcher',
version=launcher.__version__,
install_requires=['pyaml',
'boto3'
],
description='RosAPI launcher',
long_description=long_description,
packages=['launcher'],
include_package_data=True,
platforms='any',
classifiers = [
'Programming Language :: Python',
'Natural Language :: English'
]
)
The answer I found is this:
python3 setup.py bdist_wheel
doesn't write the results anyplace I can find them.
python3 setup.py bdist_wheel -d .
writes it, well, right here.
If I got you right, you search for resulting .whl file in ./build/... directory. But resulting files, both source distribution and wheel, usually by default get created in the ./dist/ directory, which is located near the build directory. Have you searched there?

Why isn't py2exe creating an executable?

A few days ago I was able to create a Windows executable of my package using py2exe with no trouble. Today I tried again after completing deleting the build/ and dist/ folders and I don't see any errors, but I also don't get an executable in my dist/ folder. I do get these files in dist/:
_hashlib.pyd
bz2.pyd
library.zip
python27.dll
select.pyd
unicodedata.pyd
Here's my setup.py file:
from setuptools import setup
import py2exe
setup (
name = "RabbitToRaven",
version = "0.1",
description="RabbitToRaven is a utility for copying RabbitMQ messages into a RavenDB database.",
author="Greg Major",
author_email="", # Removed to limit spam harvesting.
url="http://www.gregmajor.com/",
packages=['RabbitToRaven'],
entry_points = {
'console_scripts': ['RabbitToRaven = RabbitToRaven.__main__:main']
},
download_url = "http://www.gregmajor.com/",
zip_safe = True
)
If I run $ python setup.py build with export DISTUTILS_DEBUG=1 then I get this:
options (after parsing config files):
options (after parsing command line):
option dict for 'aliases' command:
{}
option dict for 'build' command:
{'verbose': ('command line', 1)}
running build
Distribution.get_command_obj(): creating 'build' command object
setting options for 'build' command:
verbose = 1 (from command line)
running build_py
Distribution.get_command_obj(): creating 'build_py' command object
creating build
creating build\lib
creating build\lib\RabbitToRaven
copying RabbitToRaven\__init__.py -> build\lib\RabbitToRaven
copying RabbitToRaven\__main__.py -> build\lib\RabbitToRaven
Here's my python setup.py py2exe output:
options (after parsing config files):
options (after parsing command line):
option dict for 'aliases' command:
{}
option dict for 'py2exe' command:
{}
running py2exe
Distribution.get_command_obj(): creating 'py2exe' command object
Distribution.get_command_obj(): creating 'bdist' command object
Distribution.get_command_obj(): creating 'build' command object
setting options for 'build' command:
running build_py
Distribution.get_command_obj(): creating 'build_py' command object
creating build
creating build\lib
creating build\lib\RabbitToRaven
copying RabbitToRaven\__init__.py -> build\lib\RabbitToRaven
copying RabbitToRaven\__main__.py -> build\lib\RabbitToRaven
creating c:\Users\Greg\Code\LeadPipe.RabbitToRaven\build\bdist.win-amd64
creating c:\Users\Greg\Code\LeadPipe.RabbitToRaven\build\bdist.win-amd64\winexe
creating c:\Users\Greg\Code\LeadPipe.RabbitToRaven\build\bdist.win-amd64\winexe\collect-2.7
creating c:\Users\Greg\Code\LeadPipe.RabbitToRaven\build\bdist.win-amd64\winexe\bundle-2.7
creating c:\Users\Greg\Code\LeadPipe.RabbitToRaven\build\bdist.win-amd64\winexe\temp
creating c:\Users\Greg\Code\LeadPipe.RabbitToRaven\dist
*** searching for required modules ***
*** parsing results ***
creating python loader for extension 'unicodedata' (C:\tools\python2\DLLs\unicodedata.pyd -> unicodedata.pyd)
creating python loader for extension 'select' (C:\tools\python2\DLLs\select.pyd -> select.pyd)
creating python loader for extension '_hashlib' (C:\tools\python2\DLLs\_hashlib.pyd -> _hashlib.pyd)
creating python loader for extension 'bz2' (C:\tools\python2\DLLs\bz2.pyd -> bz2.pyd)
*** finding dlls needed ***
*** create binaries ***
*** byte compile python files ***
byte-compiling C:\tools\python2\Lib\StringIO.py to StringIO.pyc
snip!!!
byte-compiling c:\Users\Greg\Code\LeadPipe.RabbitToRaven\lib\warnings.py to warnings.pyc
*** copy extensions ***
copying C:\tools\python2\DLLs\_hashlib.pyd -> c:\Users\Greg\Code\LeadPipe.RabbitToRaven\dist
copying C:\tools\python2\DLLs\bz2.pyd -> c:\Users\Greg\Code\LeadPipe.RabbitToRaven\dist
copying C:\tools\python2\DLLs\select.pyd -> c:\Users\Greg\Code\LeadPipe.RabbitToRaven\dist
copying C:\tools\python2\DLLs\unicodedata.pyd -> c:\Users\Greg\Code\LeadPipe.RabbitToRaven\dist
*** copy dlls ***
copying C:\Windows\system32\python27.dll -> c:\Users\Greg\Code\LeadPipe.RabbitToRaven\dist
setting sys.winver for 'c:\Users\Greg\Code\LeadPipe.RabbitToRaven\dist\python27.dll' to 'RabbitToRaven'
*** binary dependencies ***
Your executable(s) also depend on these dlls which are not included,
you may or may not need to distribute them.
Make sure you have the license if you distribute any of them, and
make sure you don't distribute files belonging to the operating system.
USER32.dll - C:\Windows\system32\USER32.dll
SHELL32.dll - C:\Windows\system32\SHELL32.dll
ADVAPI32.dll - C:\Windows\system32\ADVAPI32.dll
WS2_32.dll - C:\Windows\system32\WS2_32.dll
GDI32.dll - C:\Windows\system32\GDI32.dll
KERNEL32.dll - C:\Windows\system32\KERNEL32.dll
Anybody have an idea? I'm pretty new to py2exe so I'm sure it's probably just a silly oversight. For what it's worth, my virtualenv environment is activated and I'm building from a Bash for Git terminal (although cmd.exe doesn't work either).
You aren't specifying which file should be made into an executable. Or at least not in a way that py2exe understands. entry_points and console_scripts seem to be options unique to setuptools.
Add either
console=['name_of_script.py']
or
windows=['name_of_script.py']
as a parameter to your setup() function inside the setup.py file. Depending on if you're creating a console or GUI application. These need to be lists, even if you're specifying only a single python script, although you can add more if you'd like.
Assuming you're creating a console application, your setup function should look something like this.
setup (
name = "RabbitToRaven",
version = "0.1",
console = ['name_of_script.py'],
...)
See http://www.py2exe.org/index.cgi/ListOfOptions for all the py2exe options.

Categories

Resources