Pack python library to one file [closed] - python

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I want to pack pure python library into one source python script. (not exe, app, etc. I need exactly lib.py file) Is it possible? Which tools are exist for this?

Best is to pack all your python files into a zip: https://blogs.gnome.org/jamesh/2012/05/21/python-zip-files/
If you really want to, sure, it is possible to pack everything (including a zip I think) to a .py file, just write your custom importhook, store base64-encoded zip archive as a string in your since python source, a bit of hardcore magic here and there and voila, single python program,
Alternatively you could refactor all your dependencies and include these as classes for example in your source, but why bother?
Finally, there's no simple way to include compiled dependencies, i.e. those .so / .dylib / .dll files.
I don't think there is a tool out there that does exactly what you want, but I reckon pyinstaller/py2exe can be used to get pretty close, for example http://www.py2exe.org/old/ look for library.zip.

Related

Python code sharing and repositories? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I do scientific computing and am currently using MATLAB. I have however recently started learning Python. I find the MATLAB Central file exchange very helpful and people share a lot of their programs there.
Are there equivalent code repositories and places where people share the programs they have written for the Python community? Especially for engineering and scientific computing.
Since programming in Python revolves around using modules and packages, you might find Python's package index PyPI very useful. It allows you to easily integrate other people's code into your programs.
If you're more interested in finding out how some thing were implemented, then you might want to explore code on github. There is a ton of code out there, so you should be able to profit from it.
In case you're interested in figuring out how to use some library for scientific computing, you can find detailed examples for numpy, scipy, matplotlib and so on.
This might serve you as a good starting point for exploring Python code and examples.
The scipy Cookbook has small pieces of code, but they should only receive general-purpose and good-quality code:
http://wiki.scipy.org/Cookbook
Or the python package index:
https://pypi.python.org/pypi

RSYNC compare folder to tarfile [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I have googled a bit and it seems that you can not make an incremental backup of a folder when you compare it to the same folder in a tarformat.
I doubt that uncompressing the folder then rsycing it and recompressing the folder is a fast way to get the job done.
Do any of you have a workaround or alternative to rsync to solve this problem?
I am using cygwin on my Windows machine (at work) and cannot test the tar command, but I believe the file will be updated and you will NOT be left with two copies of the file. I know the zip command works:
zip -ru dest/test.tar src
I cannot comment on performance of zip vs tar vs rsync. If you have many many files this may become worth investigating.

Can A PDF File Be Rendered in Python Without Native Code Libraries? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I know that PDF files can be viewed using Poppler and various combinations of software and programming languages, such as using Qt 4 or 5 and C or C++.
I've also seen ways to display PDFs from Python using GTK or other libraries that need to be installed on a system. I know to do any direct display, I'll have to use that.
I do not want to create PDF files. I want to be able to take a PDF file and render it, one page at a time, into a graphical format and then display the result of that page.
Is there any way to be able to render a PDF to a graphical format, like JPG, PNG, or BMP without requiring libraries that are likely in native code on whatever system is being used? For instance Poppler is in either C or C++ (I keep forgetting which) and is compiled and installed as binary libraries.
Some background that may help is that I saw a link to Kivy, which would be an easy to use cross-platform GUI toolkit for Python, but I'd need to display PDFs for some projects. I don't mind doing the extra step of having to render it, then displaying the output if it gives me more independence from needing other libraries.
Sorry, but the answer is simply going to be no. PDF rendering is difficult, and not that many libraries do it well enough to be usable.

Python library for handling Excel files (xls | xlsx) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I need a python library that could read and write Excel files with all formats (i.e xls and xlsx).
I'm new to python and I was using Java before. In Java I was using POI library and it was perfect. I need a python library with the same functionality if possible.
I know this thread hasn't been active in a while, but I thought it would be nice to add an answer here since I made a new solution to this problem.
I had this same issue so I went ahead and created a small library that includes python-excel (xlrd, xlwt) and openpyxl within it. You can find it here: https://github.com/camyoung1234/spreadsheet
Then to use it you type the exact same code as openpyxl, except you replace openpyxl with spreadsheet. When you load and save files it looks at the extension and determines which library to use for handling it.
To install it just download it, extract it, rename the folder spreadsheet-master to spreadsheet and place it in PythonXX/Lib/site-packages/ (I've only tested with Python 2.7 but it should work with others)
The README has a few examples to help you get started.
Python excel looks like a go: http://www.python-excel.org/
Also OpenPyXl may have the features you need: http://packages.python.org/openpyxl/

Python Code Obfuscation [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
Do you know of any tool that could assist me in obfuscating python code?
Your problem space is underspecified. Is this for a command-line app? Is this code supposed to be used as a library?
In addition to the two other answers, you could embed the code into a binary. When it starts, decode the code and eval the string. This works for a shared library extension as well. You could also do that with byte code, I think, but it wouldn't be as simple as calling Py_EvalCode.
py2exe or freeze are other solution, which convert the code into an executable. It just includes the code in the binary, and doesn't do any sort of serious obsfucation, but it's still harder than opening a .py file.
You could write the code in Cython, which is similar to Python and writes Python extension files in C, for use as a .so. That's perhaps the hardest of these to reverse engineer and still give you a high-level language for develoment.
They are all hackable, as are all solutions. How hard to you want it to be?
http://www.lysator.liu.se/~astrand/projects/pyobfuscate/
Or at http://freshmeat.net/projects/pyobfuscate/
I actually found a very nice project which basically converts a Python to C++ and create a binary, statically linked file.
Check this out: http://www.nuitka.net/
In many situations you can ship byte-compiled .pyc files instead of the .py source files. This gives you some level of obfuscation. As the pyobfuscate README suggests, this has limitations. But you may be able to combine the two approaches.
Python's standard library includes compileall.py. You can run this on a directory and it will generate .pyc files for all your source files. The .pyc files will only include bytecode and docstrings, and will strip out all comments. You could then copy this directory, and then run something like rm -rf $(find . -name .py) to remove the original source files.
Your best bet is to compile it using Shed Skin, an experimental Python-to-C++ compiler.
Although it doesn't do obfuscation, this Python recipe works very well for minimizing the size of Python code, including stripping out comments.

Categories