pytoshop icon indicating copy to clipboard operation
pytoshop copied to clipboard

NameError: name 'packbits' is not defined

Open InzGIBA opened this issue 6 years ago • 8 comments

  • psdwriter version:
  • Python version: 3.6.5
  • Operating System: Windows 10

Description

Write ChannelImageData

NameError: name 'packbits' is not defined

link vpn.psd

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)

InzGIBA avatar May 28 '18 12:05 InzGIBA

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.

feliperohdee avatar Jun 11 '18 02:06 feliperohdee

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.

gotraveltoworld avatar Sep 12 '18 11:09 gotraveltoworld

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

Rockheung avatar Oct 01 '18 12:10 Rockheung

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.

akash904 avatar Sep 25 '19 08:09 akash904

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

Twice22 avatar Sep 26 '19 09:09 Twice22

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

nikhilweee avatar May 21 '21 10:05 nikhilweee

Type the command below twice

pip install pytoshop -I --no-cache-dir

hanish3464 avatar Apr 20 '22 07:04 hanish3464

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.

Ruden2007 avatar Aug 15 '22 01:08 Ruden2007