pytoshop
pytoshop copied to clipboard
NameError: name 'packbits' is not defined
- psdwriter version:
- Python version: 3.6.5
- Operating System: Windows 10
Description
Write ChannelImageData
NameError: name 'packbits' is not defined
What I Did
import pytoshop
from pytoshop.user import nested_layers
with open('vpn.psd', 'rb') as fd:
psd = pytoshop.read(fd)
header = pytoshop.core.Header(version = 2)
layers = nested_layers.psd_to_nested_layers(psd)
for idx, layer in enumerate(layers):
print(layer.name)
if type(layer) == pytoshop.user.nested_layers.Image:
cim = layer.get_channel(layer.color_mode)
with open(layer.name, 'wb') as fd:
cim.write(fd, header, cim.shape)
Hi, the file packbits (cython type) is not compiled, to do it, clne this repository and run:
python setup.py install build_ext --inplace
it will compile the lib, then you can reference it from the cloned repo.
Hi, if you want to use the pip to install pytoshop, you have to install cython before to install pytoshop.
So, you can use pip install Cython
and then run pip install pytoshop
to install this library.
For example, if you use the 'virtualenv' to build your environment, you can command this script just like below:
cd 'your_project_folder'
virtualenv venv
source venv/bin/activate
pip install Cython
pip install pytoshop
Finally, you can use some codes for testing.
Now this package version is 1.2.0 on PyPI. This repository's master branch's version seems to be 1.1.0.
You can download directly from PyPI: pytoshop and untar it with tar -zxvf pytoshop-1.2.0.tar.gz
.
Then go where setup.py is and run python setup.py install
. This should not be different from pip install pytoshop==1.2.0
, but somehow so
file is not built with pip. 1.1.0 works fine on the other hand.
My dev environment is Ubuntu 18.04 LTS, and I'm using python 3.6.5 and gcc-7.3, Cython 0.28.5
open this file: C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\pytoshop\codecs.py
At the starting of the code change:
try: from . import packbits # type: ignore except ImportError: pass
TO
try: import packbits # type: ignore except ImportError: pass
Fixed.
I'm using anaconda.
I created an environment with:
conda create -n test python=3.6 pip
then
python -m pip install pytoshop
It works. The packbits.so
is generated inside the site-packages/pytoshop directory.
However, with python=3.7, I have the packbits.pyx
and not the packbits.so
file and it results in
packbits being not defined:
conda create -n test python=3. pip
python -m pip install pytoshop
If you installed pytoshop earlier, got this error, came to this issue, uninstalled pytoshop, and installed pytoshop again, pip will use the cached version. You need to disable the cache for pytoshop to compile using cython.
pip install pytoshop --no-cache-dir
Type the command below twice
pip install pytoshop -I --no-cache-dir
What worked for me is: add
import pyximport
pyximport.install()
before import line
try:
from. import packbits # type: ignore
except ImportError:
pass
in file codecs.py
Sorry for my english, I'm from Ukraine.