Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameError: name 'packbits' is not defined #9

Open
InzGIBA opened this issue May 28, 2018 · 8 comments
Open

NameError: name 'packbits' is not defined #9

InzGIBA opened this issue May 28, 2018 · 8 comments

Comments

@InzGIBA
Copy link

InzGIBA commented May 28, 2018

  • 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)

@feliperohdee
Copy link

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.

@gotraveltoworld
Copy link

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.

@Rockheung
Copy link

Rockheung commented Oct 1, 2018

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

@akash904
Copy link

akash904 commented Sep 25, 2019

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.

@Twice22
Copy link

Twice22 commented Sep 26, 2019

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

andrewvaliente added a commit to andrewvaliente/pytoshop that referenced this issue Dec 10, 2019
@nikhilweee
Copy link

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

@hanish3464
Copy link

Type the command below twice

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

@Ruden2007
Copy link

Ruden2007 commented Aug 15, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants