Open GoogleCodeExporter opened 9 years ago
When in a unicode path and importing a local PYD module (portable zip
distribution) it fails:
import cefpython_py27 as cefpython
Error:
Traceback (most recent call last):
File "wxpython.py", line 51, in <module>
import cefpython_py27 as cefpython
ImportError: No module named cefpython_py27
It also fails with "import cefwindow" and that's a regular python file
"cefwindow.py". So this is not an issue with the PYD module built with Cython.
Maybe that's not an issue when app is packaged with py2exe. But still looks
like Python 2.7 has some serious issues with unicode. So I'm not going to make
this a priority.
-------------------
THE PROPER SOLUTION
-------------------
Create a standalone installer for your application, using for example Inno
Setup (http://www.jrsoftware.org/isinfo.php). Install application to C:\Program
Files\.
Original comment by czarek.t...@gmail.com
on 8 Dec 2014 at 11:25
I've modified GetApplicationPath to return unicode path, but it's not needed
anyway. Pasting it here so that it doesn't get lost, in case I reinvestigate
this issue again later.
def GetApplicationPath(file=None):
# Returns a unicode string. To print unicode string to console:
# print(GetApplicationPath().encode(sys.stdout.encoding, "replace"))
encoding = sys.getfilesystemencoding()
if file is None:
# If file is None return current directory without trailing slash.
file = u""
else:
file = unicode(file, encoding)
# On Windows after downloading file and calling Browser.GoForward(),
# current working directory is set to %UserProfile%.
# Calling os.path.dirname(os.path.realpath(__file__))
# returns for eg. "C:\Users\user\Downloads". A solution
# is to cache path on first call.
if not hasattr(GetApplicationPath, "dir"):
if hasattr(sys, "frozen"):
os.path.dirname(unicode(sys.executable, encoding))
elif "__file__" in globals():
dir = os.path.dirname(os.path.realpath(\
unicode(__file__, encoding)))
else:
dir = os.path.dirname(os.path.realpath(u"."))
GetApplicationPath.dir = dir
# When relative path.
if not file.startswith(u"/") and not file.startswith(u"\\") and (
not re.search(r"^[\w-]+:", file)):
path = os.path.join(GetApplicationPath.dir, file)
if platform.system() == "Windows":
path = re.sub(r"[/\\]+", re.escape(os.sep), path)
path = re.sub(r"[/\\]+$", "", path)
return path
return file
if platform.architecture()[0] != "32bit":
raise Exception("Architecture not supported: %s" \
% platform.architecture()[0])
libcef_dll = GetApplicationPath("libcef.dll")
if os.path.exists(libcef_dll):
# Import a local module. A case when using a Portable Zip distribution.
if (2,7) <= sys.version_info < (2,8):
import cefpython_py27 as cefpython
elif (3,4) <= sys.version_info < (3,5):
import cefpython_py34 as cefpython
else:
raise Exception("Unsupported python version: %s" % sys.version)
else:
# Import from an installed package
from cefpython3 import cefpython
Original comment by czarek.t...@gmail.com
on 8 Dec 2014 at 11:28
[deleted comment]
Looks like cefpython can work just fine in a unicode path. One of users
reported that after packing his app using py2exe everything worked, except when
launching CEF subprocesses. So seems like imports are working just fine on
unicode paths after using py2exe. The only problem are CEF paths to the
subprocess executable and some other CEF resources. Looks like you just need to
set application settings passed to cefpython.Initialize(), that are paths, to
be unicode strings. There are a few such settings:
browser_subprocess_path
locales_dir_path
resources_dir_path
# There is also cache_path, but it's optional to set
Example proof test:
cefpython resides in "binaries/" directory. I've made a copy of it and named it "binaries ąś/". Removed subprocess.exe from "binaries/" and edited "binaries/wxpython.py" file with this line changed:
"browser_subprocess_path": u"./../binaries ąś/subprocess",
Launched "binaries/wxpython.py" and it worked fine.
So, all examples are easily fixable, with the exception when using
wx.chromectrl module. For wx.chromectrl to work, further fixes would be
required to cefpython.GetModuleDirectory() and chromectrl.py > Initialize().
Original comment by czarek.t...@gmail.com
on 8 Dec 2014 at 11:53
Original comment by czarek.t...@gmail.com
on 8 Dec 2014 at 12:32
Project will move to Github. Find this issue at the new address (soon):
https://github.com/cztomczak/cefpython/issues/151
Original comment by czarek.t...@gmail.com
on 24 Aug 2015 at 6:42
Original issue reported on code.google.com by
czarek.t...@gmail.com
on 8 Dec 2014 at 10:21