sergey-dryabzhinsky / python-zstd

Simple python bindings to Yann Collet ZSTD compression library
BSD 2-Clause "Simplified" License
165 stars 27 forks source link

How do I use this? #6

Closed the-bobo closed 8 years ago

the-bobo commented 8 years ago

Hi Sergey,

Thanks for putting this together. I think I've figured out how to install it, but am unsure how to invoke it from a script.

I try import zstd but I get a ImportError: No module named zstd

For install, this is what I did (I do not have permission to install to the system directories):

git clone https://github.com/sergey-dryabzhinsky/python-zstd 
cd python-zstd
git submodule update --init
python setup.py build clean
PYTHONPATH=<path_to_a_custom_directory> python setup.py install --install-lib=<path_to_a_custom_directory>

This results in ls <path_to_a_custom_directory> returning easy-install.pth site.py site.pyc zstd-0.6.1-py2.7-linux-x86_64.egg

Then in my code I have:

sys.path.append(<path_to_a_custom_directory>)
import zstd
  1. How do I import zstd into my script?
  2. How do I call zstd from my script? Can I do it like zlib? Example:
compressed_msg = zlib.compress(msg.encode('utf-8'), level)

Where level is an integer from 0 through 9 referring to the zlib compression level.

sergey-dryabzhinsky commented 8 years ago
  1. You can try to use pip: pip install zstd. Or pip3 for python-3.2+.
  2. Yes, it has zlib-like interface:
import zstd

cmp_data = zstd.compress(data, level)

level is an integer from 1 to 20.

the-bobo commented 8 years ago

Sorry I am new to python. For pip install, when do I do that (after python setup.py build clean?) and in what directory?

And thanks, I am using Python 2.7.5. On Jun 27, 2016 6:49 PM, "Sergey" notifications@github.com wrote:

  1. You can try to use pip: pip install zstd. Or pip3 for python-3.2+.
  2. Yes, it has zlib-like interface:

import zstd

cmp_data = zstd.compress(data, level)

level is an integer from 1 to 20.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/sergey-dryabzhinsky/python-zstd/issues/6#issuecomment-228926620, or mute the thread https://github.com/notifications/unsubscribe/AEIej9M3GLea5kPC3eXdY5M_HPQXrZVRks5qQH2RgaJpZM4I_kik .

sergey-dryabzhinsky commented 8 years ago

You do that any time in any directory. Better by root user. pip is a package manager for Python - https://pip.pypa.io/en/stable/. It uses python packages repository - https://pypi.python.org/pypi

In Ubuntu/Debian distro install it with apt-get install python-pip python3-pip

sergey-dryabzhinsky commented 8 years ago

And if you need to import module from custom dir, prepend path to sys.path:

sys.path.insert(0, <path_to_a_custom_directory>)
the-bobo commented 8 years ago

Ok cool, if I want to install zstd in a specific directory can I do that with pip install? Should I just use venv instead? Not sure what best practice is here.

Thanks so much Sergey. Once I get it working I may submit a pull request with easier setup instructions for n00bs to your README.md if that's okay. On Jun 27, 2016 10:45 PM, "Sergey" notifications@github.com wrote:

And if you need to import module from custom dir, prepend path to sys.path:

sys.path.insert(0, )

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/sergey-dryabzhinsky/python-zstd/issues/6#issuecomment-228954084, or mute the thread https://github.com/notifications/unsubscribe/AEIej5yBIVBQo741i4yU2InzGdE5H7Zsks5qQLTigaJpZM4I_kik .

the-bobo commented 8 years ago

I fixed this by changing:

sys.path.append(<path_to_a_custom_directory>)
import zstd

to

sys.path.append(<path_to_a_custom_directory>/zstd-0.6.1-py2.7-linux-x86_64.egg>)
import zstd

zstd.compress(data, level)now works