﻿<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ja">
	<id>https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=Dev%3A2.5%2FSource%2FPython%2FAPI%2FPy3.1_Migration</id>
	<title>Dev:2.5/Source/Python/API/Py3.1 Migration - 版の履歴</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=Dev%3A2.5%2FSource%2FPython%2FAPI%2FPy3.1_Migration"/>
	<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:2.5/Source/Python/API/Py3.1_Migration&amp;action=history"/>
	<updated>2026-05-18T16:39:45Z</updated>
	<subtitle>このウィキのこのページに関する変更履歴</subtitle>
	<generator>MediaWiki 1.31.0</generator>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=Dev:2.5/Source/Python/API/Py3.1_Migration&amp;diff=89231&amp;oldid=prev</id>
		<title>Yamyam: 1版 をインポートしました</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:2.5/Source/Python/API/Py3.1_Migration&amp;diff=89231&amp;oldid=prev"/>
		<updated>2018-06-28T18:42:28Z</updated>

		<summary type="html">&lt;p&gt;1版 をインポートしました&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ja&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← 古い版&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;2018年6月28日 (木) 18:42時点における版&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ja&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(相違点なし)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Yamyam</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=Dev:2.5/Source/Python/API/Py3.1_Migration&amp;diff=89230&amp;oldid=prev</id>
		<title>wiki&gt;Ideasman42: /* Python 3.x migration proposal */</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:2.5/Source/Python/API/Py3.1_Migration&amp;diff=89230&amp;oldid=prev"/>
		<updated>2015-11-05T06:56:43Z</updated>

		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Python 3.x migration proposal&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新規ページ&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Python 3.x migration proposal =&lt;br /&gt;
A while ago we agreed (general consensus)&lt;br /&gt;
* bundle python with blender on all OS's&lt;br /&gt;
* include all python modules with blender so scripts work without worrying about system python. (with the exception of test, distutils, and tk) ~4mb last I checked on win32.&lt;br /&gt;
* to use a single version of python not mix (no need to support both 2.x and 3.x)&lt;br /&gt;
'''Refer to the mail thread...'''&amp;lt;br&amp;gt;&lt;br /&gt;
http://lists.blender.org/pipermail/bf-committers/2008-December/022295.html&lt;br /&gt;
&lt;br /&gt;
Trying to support 2.x and 3.x wastes too much time with the C/API and also becomes problematic for script compatibility.&lt;br /&gt;
Since python 3.x now has a stable release I think now is a good time to make the move.&lt;br /&gt;
&lt;br /&gt;
== Status ==&lt;br /&gt;
* Blender 2.5 builds against python 3.x&lt;br /&gt;
* User interface scripts in blender 2.5 currently run 3.x&lt;br /&gt;
* Python 3.x is included in the &amp;quot;lib&amp;quot; folder (used by windows and mac builds)&lt;br /&gt;
* On Windows all of Python 3.x modules/libraries are bundled with Blender. If built with scons, a complete package including Python 3.x is found in BF_INSTALLDIR. With other build systems the Python zip from lib/windows/release or lib/win64/release needs to be extracted to the correct location (.blender/scripts/python/lib)&lt;br /&gt;
&lt;br /&gt;
==Including the Python Library==&lt;br /&gt;
This means distributing blender without the dependency on libpython3.x.so, or python3x.dll on windows. &lt;br /&gt;
(Only our windows releases currently do this)&lt;br /&gt;
&lt;br /&gt;
For all other OS's (unix based) we can either statically link libpython3.x.a to blender when building or include libpython3.x.so with blender.&lt;br /&gt;
&lt;br /&gt;
I don't mind either way; however if we include the library separately we'll need to start blender with a shell script to set the LD_LIBRARY_PATH (firefox, maya and many other apps that include their own separate libs on linux, using a shell script to start).&lt;br /&gt;
&lt;br /&gt;
We could do static linking to start with, its easy to change later on, can be decided per OS.&lt;br /&gt;
&lt;br /&gt;
==Including Python Modules==&lt;br /&gt;
''Note that on Windows since Blender 2.5 Alpha 0 below directions, including the next section, are no longer necessary. Everything is ready in BF_INSTALLDIR''&lt;br /&gt;
&lt;br /&gt;
Python modules are a mixture of .py files and compiled modules (.so files on linux)&lt;br /&gt;
&lt;br /&gt;
This means copying /usr/lib/python3.x into some directory blender can be bundled with eg. ~/.blender/python (from C:\Python3x\Lib on windows)&lt;br /&gt;
&lt;br /&gt;
''Note that blender won't start unless these modules are found (error below), so it's important to get this path right.''&lt;br /&gt;
 Fatal Python error: Py_Initialize: can't initialize sys standard streams&lt;br /&gt;
 ImportError: No module named encodings.utf_8&lt;br /&gt;
&lt;br /&gt;
Python then needs to know to use this path for the modules rather than /usr/lib/python3.x&lt;br /&gt;
There are a number of ways to do this....&lt;br /&gt;
# Define our own Py_GetPath() that overrides pythons. See http://docs.python.org/c-api/init.html&lt;br /&gt;
# Set the PYTHONPATH and PYTHONHOME (from C) before initializing python.&lt;br /&gt;
# Start with a shell script that sets the PYTHONPATH/PYTHONHOME (all except win32).&lt;br /&gt;
&lt;br /&gt;
=== What about zipping the modules ===&lt;br /&gt;
Python supports reading modules from a zip file rather than a directory. While the option is always open, I'm against this for a number of reasons.&lt;br /&gt;
# Py3.x by default builds without zlib modules in libpython3.x.so; this means loading a zip as a module fails unless you build python with and edited Modules/Setup&amp;lt;br&amp;gt;''*Note* I only tested this on linux, perhaps windows or mac are different since python26.zip works on windows for blender 2.4x. because zlib.pyd is outside the zip''&lt;br /&gt;
&lt;br /&gt;
# a small zip is fast to extract but the bundle will be around 4mb (compressed), a larger file could become slow - since this will be read on initializing blender/python.&lt;br /&gt;
# We might want to include more modules (numpy, pygame, PIL for eg), at some point an even larger zip file could slow down blender's startup time.&lt;br /&gt;
&lt;br /&gt;
The assumption about speed would need to be verified but needing to edit Modules/Setup before building python is reason enough for me not to do this.&lt;br /&gt;
&lt;br /&gt;
=== Removing Modules ===&lt;br /&gt;
&lt;br /&gt;
Directory's in the lib dir that can be removed.&lt;br /&gt;
* test&lt;br /&gt;
* distutils&lt;br /&gt;
* lib2to3&lt;br /&gt;
* idlelib&lt;br /&gt;
* tkinter&lt;br /&gt;
* config (not a module but contains files we don't need)&lt;br /&gt;
&lt;br /&gt;
Test Modules...&lt;br /&gt;
* ctypes/test&lt;br /&gt;
* email/test&lt;br /&gt;
* importlib/test&lt;br /&gt;
* json/test&lt;br /&gt;
* sqlite3/test&lt;br /&gt;
&lt;br /&gt;
Dynamic libs&lt;br /&gt;
* lib-dynload/_tkinter.so&lt;br /&gt;
&lt;br /&gt;
Also...&lt;br /&gt;
* all *.pyc and *.pyo files&amp;lt;br&amp;gt;rm `find -name &amp;quot;*.pyo&amp;quot;`&amp;lt;br&amp;gt;find -name &amp;quot;*.pyc&amp;quot;`&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Strip dynamic libs to save space&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 strip -s lib-dynload/*.so&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proposal ==&lt;br /&gt;
Even though there are many options I think these should be the least hassle for devs and users.&lt;br /&gt;
&lt;br /&gt;
* statically link python on all OS's (except windows which can include the DLL)&lt;br /&gt;
* distribute python modules in a directory with blender (~/.blender/python)&lt;br /&gt;
* include Python3.x in the lib/ directory.&amp;lt;br&amp;gt;''Linux devs have the option to use the lib folder or install python 3.x on their system.''&lt;br /&gt;
&lt;br /&gt;
Advantages with this method are...&lt;br /&gt;
* developers who have python3.x currently won't notice any difference&amp;lt;br&amp;gt;(since system's python is still used).&lt;br /&gt;
* our own python library will be used, which is predictable for users.&lt;br /&gt;
* static linking, no need for shell scripts to start the blender binary on unix.&lt;br /&gt;
&lt;br /&gt;
=== Tasks ===&lt;br /&gt;
* Use ~/.blender/python for modules. '''Done''' - rev 21334, falls back to system python if not found&lt;br /&gt;
* add pre-built python to the lib/ dir for MacOS/Windows/Linux '''(done)'''&lt;br /&gt;
* make static linking python default on MacOS and Linux. '''(not urgent)'''&lt;br /&gt;
* building release should copy modules into .blender/python '''(done)'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[User:Ideasman42|Ideasman42]] 01:26, 3 July 2009 (UTC)(Sign)&lt;br /&gt;
&lt;br /&gt;
== See also==&lt;br /&gt;
&lt;br /&gt;
[[Dev:Doc/Building_Blender/Linux/Troubleshooting#Python]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Script]]&lt;br /&gt;
&lt;br /&gt;
= Python Upgrade Policy =&lt;br /&gt;
This section has been added after discussion on the bf-committers mailing list, see: [http://markmail.org/message/he6psf37br6szwzz]&lt;br /&gt;
&lt;br /&gt;
When upgrading from versions of python 3.2 -&amp;gt; 3.3 for eg.&lt;br /&gt;
This is problematic for Linux since we dont provide pre-compiled libs.&lt;br /&gt;
&lt;br /&gt;
From discussion after 3.1 -&amp;gt; 3.2 upgrade here are steps we should take before dropping support for the previous python version.&lt;br /&gt;
* All platform maintainers first agree to drop support.&lt;br /&gt;
* Mail the list beforehand and include a note in meeting minutes that the python version will be no longer supported.&lt;br /&gt;
* Ensure build instructions are up to data for Ubuntu/Fedora to install packages (most likely from testing repo's).&lt;/div&gt;</summary>
		<author><name>wiki&gt;Ideasman42</name></author>
		
	</entry>
</feed>