<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>venv Archives - Creatronix</title>
	<atom:link href="https://creatronix.de/tag/venv/feed/" rel="self" type="application/rss+xml" />
	<link>https://creatronix.de/tag/venv/</link>
	<description>My adventures in code &#38; business</description>
	<lastBuildDate>Wed, 11 May 2022 07:08:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Overcoming PyInstaller Pitfalls</title>
		<link>https://creatronix.de/overcoming-pyinstaller-pitfalls/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Tue, 09 Jul 2019 07:30:45 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[PyInstaller]]></category>
		<category><![CDATA[venv]]></category>
		<guid isPermaLink="false">http://creatronix.de/?p=2797</guid>

					<description><![CDATA[<p>When using PyInstaller to package an application to a self-containing bundle you might run into some pitfalls: Pitfall 1: PyInstaller overwrites spec file The first time you run pyinstaller you run it with pyi-makespec my_module.py instead of pyinstaller my_module.py pyi-makespec will generate a my_module.spec which you can alter. Afterwards you just ran pyinstaller my_module.spec to&#8230;</p>
<p>The post <a href="https://creatronix.de/overcoming-pyinstaller-pitfalls/">Overcoming PyInstaller Pitfalls</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>When using PyInstaller to package an application to a self-containing bundle you might run into some pitfalls:</p>
<h2>Pitfall 1: PyInstaller overwrites spec file</h2>
<p>The first time you run pyinstaller you run it with</p>
<pre>pyi-makespec my_module.py</pre>
<p>instead of</p>
<pre>pyinstaller my_module.py</pre>
<p>pyi-makespec will generate a my_module.<strong>spec </strong>which you can alter. Afterwards you just ran</p>
<pre>pyinstaller my_module.<strong>spec</strong></pre>
<p>to avoid overwriting the spec file.</p>
<h2>Pitfall 2: Packing additional resources</h2>
<p>If You want to have additional files in your distribution you can alter the .spec file:</p>
<pre>a = Analysis(['my_module.py'],
             pathex=['C:\\Users\\jrb\\PycharmProjects\\pyinstaller_test'],
             binaries=[],
            <strong> datas=[("docs/user_manual.txt", ".")]</strong>,</pre>
<h2>Pitfall 3: Templates not found after packaging</h2>
<p>If you are using for example a templating engine like jinja2 and have to access the templates from the distribution you have to fiddle with the path:</p>
<pre>path = os.getcwd()
if getattr(sys, 'frozen', False):
    logger.debug("We are running in a bundle!")
    path = getattr(sys, '<strong>_MEIPASS</strong>', os.getcwd())
    logger.debug("Bundle path" + path)

file_loader = FileSystemLoader(os.path.join(path, 'templates'))
env = Environment(loader=file_loader)
template = env.get_template('template.html')</pre>
<h2>Pitfall 4: Running PyInstaller from an virtual environment</h2>
<p>When running PyInstaller from inside a virtual environment you sometimes get</p>
<pre> File "C:\Python37\lib\ntpath.py", line 183, in split
p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType</pre>
<p>In that case you can pactch venv/Lib/site-packages/PyInstaller/depend/bindepend.py with the following snippet:</p>
<pre># Work around for python venv having VERSION.dll rather than pythonXY.dll
if is_win and 'VERSION.dll' in dlls:
    pydll = 'python%d%d.dll' % sys.version_info[:2]
    if pydll in PYDYLIB_NAMES:
        filename = getfullnameof(pydll)
        return filename</pre>
<p><a href="https://github.com/Loran425/pyinstaller/commit/14b6e65642e4b07a4358bab278019a48dedf7460">Source: github link</a></p>
<h2>Pitfall 5: Making a single file executable</h2>
<p>When You want to get a single file executable you can use the -F flag (or &#8211;onefile) for generating the .spec-file. This works only when you have no additional data which should be copied 🙂</p>
<pre>pyi-makespec -F my_module.py</pre>
<h2>Pitfall 6: ModuleNotFoundError: No module named &#8216;_socket&#8217;</h2>
<p>I&#8217;ve ran into a diverse set of issues where modules weren&#8217;t found.</p>
<p>Packaged programs seem to be unable to run from network drives directly.</p>
<p>It is always a good idea to also clean the cashes</p>
<p>on Windows: %APPDATA%\pyinstaller (or ~\Application Data\pyinstaller)</p>
<h2>Troubleshooting guide</h2>
<p><a href="https://github.com/pyinstaller/pyinstaller/wiki/How-to-Report-Bugs">https://github.com/pyinstaller/pyinstaller/wiki/How-to-Report-Bugs</a></p>
<p>&nbsp;</p>
<p>The post <a href="https://creatronix.de/overcoming-pyinstaller-pitfalls/">Overcoming PyInstaller Pitfalls</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
