如何构建多个兼容Python 2.7+和3.3+兼容的相同命名空间的python模块?
让我们调用命名空间test.现在我想要调用两个单独的模块test.foo,另一个调用test.bar.但是,我目前正在开发test.helloworld,这取决于两者,test.foo和test.bar.两者都列在requirements.txt文件中.
这些模块test.foo和test.bar目前正在使用的Python 2解决方案的命名空间的包:
import pkg_resources
pkg_resources.declare_namespace(__name__)
Run Code Online (Sandbox Code Playgroud)
为开发模式 运行建议的pip-commandpip install -e .将变为: ImportError: No module named 'test.helloworld'导入test.foo或test.bar正在运行时.
用于命名空间包的Python 3解决方案是隐式命名空间包,其中命名空间包没有__init__.py文件.遗憾的是,这不适用于Python 2版本.
如何为Python 2和3设计解决方案(允许我使用pip install -e .)?该--egg解决方案对我不起作用,因为它已被弃用.
我偶然发现了这篇文章并遵循了所有步骤.但pyDev不会看到我的烧瓶扩展,这真的很烦人.只有一件事(我认为这是关键):
Touch /site-packages/flaskext/__init__.py
Touch我认为是unix util.在Windows上是否有相同的功能?
当我尝试使用PIL打开EPS或SVG图像时,我遇到了几个问题.
打开EPS
from PIL import Image
test = Image.open('test.eps')
Run Code Online (Sandbox Code Playgroud)
结束于:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\Lib\site-packages\PIL\Image.py", line 1965, in open
return factory(fp, filename)
File "C:\Python27\Lib\site-packages\PIL\ImageFile.py", line 91, in __init__
self._open()
File "C:\Python27\Lib\site-packages\PIL\EpsImagePlugin.py", line 206, in _open
raise IOError, "bad EPS header"
IOError: bad EPS header
Run Code Online (Sandbox Code Playgroud)
打开SVG结束IOError: cannot identify image file.
问题是我必须在我的应用程序中支持这两种格式.转换为其他格式是别无选择.我使用的是Windows 7,Python 2.7.2和PIL 1.1.7.
python ×3
eclipse ×1
eps ×1
flask ×1
pip ×1
pydev ×1
python-2.7 ×1
python-3.x ×1
setup.py ×1
svg ×1