So, the title basically covers my question. I've created a project using virtualenv, e.g. I have to
source ./env/bin/activate
to run my script.
When I try creating an executable using:
pyinstaller --onefile <myscript.py>
None of the virtualenv packages are included; just the ones that are installed globally. I have a requirements.txt file that contains all of the modules I need. Is there a way to have pyinstaller point to that for the needed modules, or is there another way?
As Valentino pointed out by looking at How can I create the minimum size executable with pyinstaller?
You have to run PyIntaller from inside the virtual environment:
(venv_test) D:\testenv>pyinstaller
How to solve the not importing modules from the virtual environment
The virtual environment saves modules in a different directory than the global module directory. If you are using Windows like me, you can find the modules directory here:
C:\Users\<your username>\.virtualenvs\<your project name>\Lib\site-packages
When you find your virtualenv directory, run this command instead of this simple command(pyinstaller <script>.py):
pyinstaller --paths "C:\Users\<your username>\.virtualenvs\<your project name>\Lib\site-packages" --hidden-import <module name that should be import> <your script name>.py
To export just one file you can add this: -F or --onefile
As many modules as you can add to be imported by adding more --hidden-import flags and module name
Flag description
--paths: The pyinstaller will search for imports here
--hidden-import: Which modules should be imported by pyinstaller from the path
Related
I have a python file that I am trying to create an executable out of using Pyinstaller on my Mac. This python file imports several different python files. When I run the unix executable that was generated, I get this error:
File "main/__init__.py", line 4, in <module>
ModuleNotFoundError: No module named 'game'
Line 4 reads:
from game.scripts.gui import creator
The command I used to create the executable:
pyinstaller __init__.py --onefile --clean --windowed
The directory:
__init__.py
game
scripts
gui
creator.py
Any ideas on how I could fix this? Thanks
The subdirs are not included by creating an *.exe, so the creator.py is not found inside your *.exe. To avoid that, you have to include the extra files/folders by specifying them. This can be done by a *.spec file
By calling pyinstaller with your *.py file it will create a default *.spec file which you can edit and use next time to create your *.exe. Every option you used when calling
pyinstaller __init__.py --onefile --clean --windowed
is configured here so calling
pyinstaller *.spec
the next time gives the same result.
Edit this in your spec-file to fit your needs by copying single files or even whole folders including their content into the *.exe:
a = Analysis(['your.py'],
pathex=['.'],
binaries=[],
datas=[('some.dll', '.'),
('configurationfile.ini', '.'),
('data.xlsx', '.'),
('../../anotherfile.pdf', '.')
],
....some lines cut ....
a.datas += Tree('./thisfoldershouldbecopied', prefix='foldernameinexe')
More infos to that are found in the docs of pyinstaller regarding spec-files and including data files
https://pyinstaller.readthedocs.io/en/stable/spec-files.html
and for example in this post here:
Pyinstaller adding data files
In my projects folder i have a folder with the name translations where i have the translations files .ts.
What i want Qt/QMake to do on run is to put on the build folder the translation with the correspondent .qm files.
How can this be done?
You can run shell commands with qmake, using a custom target. Have a look at this answer here on SO.
In this case the command to invoke is lurelease, providing the right paths to your ts files and output directory.
Be aware custom commands are evaluated using the shell of the OS running qmake. That is cmd.exe on Windows and (likely) bash in several unix like systems. Therefore, a qmake script with custom commands is not platform agnostic.
Could someone please explain how one uses the premake extensions. I added the eclipse extension in a directory under my premake installation. And in the premake script I added recuire "eclipse".
Running the script with premake5 eclipse, I get an error module "eclipse.lua" not found.
I added the path of the modules directory to my environment variables.
I'm using premake (premake5) on Windows 8.
Thanks
addons need to reside in a folder. You need to create a "eclipse" folder, then copy all the files in it, and the "eclipse" folder should be located where premake can load it (either next the executable or some other place handled through environment variables)
I got this working by adding the full path to the require statement.
require "C:/premake/eclipse/eclipse"
and running the command as premake5 eclipse
Note: This plugin does not generate project files that one can import into Eclipse.
I've just installed the Qt5.2.1 (/opt/qt-5.2.1/5.2.1/gcc64) on my Ubuntu 13.10. I previuosly installed a Qt5.1 in my home directory.
When call designer, an error raised
designer: could not exec '/usr/lib/x86_64-linux-gnu/qt5/bin/designer
I've seen that this target points to a qtchooser program. In the docs it's used for to switch between different Qt versions. Very usefull as this configuration can be applied system wide.
I would like to configure it but based on the qtchooser manpage , the configuration files should be located at
/etc/xdg/qtchooser/.conf*. In Ubuntu 13.10 there's no such directory and no information about the file names and their internal structure but a line for the binaries path and one line for the library path, a default conf file that would contain the default path?
I created the desired qtchooser directory with a default.conf file containing my lib and bin path. Nothing changed when I ran qtchooser --list-version, always the same list is displayed:
qtchooser --list-versions
outputs :
jeby6372#mercure:/opt$ qtchooser --list-versions
qt5-x86_64-linux-gnu
5
default
qt5
I don't understand where these informations are stored so that I could manage the swap beetween my 2 versions.
Or at least , is it possible to disconnect qtchooser without removing the Qt products?
Any Idea?
In Ubuntu 13.10, the configuration files are stored here:
/usr/lib/i386-linux-gnu/qtchooser/
I simply added new conf file, copying from one existing (e.g. qt521.conf) edited changed the path to the new QT5.2.1, configured qtchooser to use the new conf file with
export QT_SELECT=qt521
and now I can call qmake using the QT5.2.1 environment.
I'm currently transferring a project built with qmake to CMake.
In the version with qmake, in the .pri file, there was
MOC_DIR = .moc/$${PLATFORM_NAME}
that permitted to produce the MOC temporary files in a given directory, keeping the sources clean. How to do the same thing with CMake?
Note: with CMake, I use the FindQt4.cmake package and the command QT4_WRAP_CPP().
As baysmith says, if your goal is to keep your source directory clean, the real solution is to use CMake's "out-of-source" builds feature. If you're on Windows, set "Where to build the binaries" to a new directory, different from the "Where is the source code" directory. If you're on Unix, it goes something like this:
cd <source directory>
mkdir build
cd build
cmake ..
make
By running CMake on a different directory, all of the build files will go into that directory, and your sources will stay clean. (Note: the build directory doesn't have to be inside the source directory. See the CMake wiki for more details.)
If "out-of-source" doesn't work for you, I was able to find one other option. Based on what I can tell from the Qt4Macros.cmake file installed with my CMake 2.8, it isn't accessible as a config parameter. Here's the relevant line:
SET(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_current_MOC})
The workaround is to change all of your MOC include directives to specify the subfolder you'd like to build to.
#include "moc/mainwindow.moc"
After creating the moc directory inside my build directory, there were no problems building, and my MOC file was in the new directory.