When I installed Python Markdown, I noticed that it added files to a build/docs/extensions folder. Where can I find this folder? I've searched through my machine, but came up empty.
As part of the build process, Python-Markdown also builds the docs (from Markdown text files into HTML files). However, as the generated files are written to the build directory, they are deleted in the cleanup step after install (the build dir is deleted). The docs are hosted here, but if you would like a local copy, you can build them yourself.
First you need a copy if the source files either from PyPI or GitHub. then from within the top directory, run the following command:
python setup.py build_docs
The docs will be written to build/docs. As we didn't complete the install process, the files haven't been deleted yet.
The complete steps to download and build might look this (on Linux using the current release of Python-Markdown):
wget http://pypi.python.org/packages/source/M/Markdown/Markdown-2.5.2.tar.gz
tar xvzf Markdown-2.5.2.tar.gz
cd markdown-2.5.2/
python setup.py build_docs
cd build/docs
From that point you can move/copy the files to wherever you would like them, or open them in your browser of choice to view them.
Related
I have a python project which takes in a bunch of pdf files from a directory, scrapes data from them, and then does some matching of that scraped data with some data in a CSV file.
The whole work has 2-3 python scripts, used as modules, and also uses dependencies of pdftotext, pandas, NumPy, etc.
Now I can pip freeze my Conda env and it can give me a requirements.txt file with all packages to install.
However, I want this main python script (which calls other modules and runs the whole project) to be run by a less technical person who doesn't work on pandas and other such python stuff.
So is there a way I can make this whole project as an executable file that encapsulates all dependencies, packages, scripts, and just running that executable in the terminal should run the whole project without having the other person install all dependencies themselves using requirements.txt file.
I can't use docker unfortunately as that is not permitted right now for my work.
I was thinking buck build if that works?
https://buck.build/
or if there is an easy way?
Thanks!
One approach is to package the Python application directory as a .zip file and execute that. Zip files that have a __main__.py entry point can be run this way.
This can be done easily in version 2.6 and up. Additional “zipapp” support was added in 3.6.
The main challenge has to do with compatibility for non-pure-Python libraries. What you zip up needs to be compatible with the machine where it will be run.
pip install cx_freeze
cxfreeze main.py --target-name your_exe_name
Replace your_exe_name. It will generate a build folder with your .exe in it.
I'm new to python. I have a maven project which uses the org.jolokia maven-docker-plugin to create a docker image that consumes a python library.
Currently the container uses a pip install to install the python library.
I have forked the python library and made some changes, and now I would like my docker container to consume MY version of the python library. How can I do this?
What I have tried:
Copied my changed python file to overwrite the folder located in /usr/local/lib/python2.7/dist-packages/ which was generated after pip install (via mount directory into container).
Created tar of entire python project, added it into image using fileSets, ran pip install /maven/mypythonversion.tar.gz.
Any help much appreciated!
The way to do this is to get your python project into the image and run install on the setup.py. This method assumes your image already has the python interpreter and the relevant dependencies installed for your project to run.
Copy your python project code into a folder in your maven project i.e. one called input.
Use fileSets in the assembly of the image to assemble the python source code into the image. <directory> should point to the input folder containing your python source code:
<assembly>
<mode>tar</mode>
<inline>
<fileSets>
<fileSet>
<directory>C:/.../input</directory>
<outputDirectory>/output</outputDirectory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
</fileSets>
</inline>
</assembly>
Then you want a script to run python setup.py install from the output directory (/maven/output/mypythonproject).
I.e. use a runCmd:
<runCmds>
<run>
cd /maven/output/mypythonproject \
python setup.py install
</run>
</runCmds>
This installs the python module and puts egg file in the /usr/local/lib/python27/dist-packages folder, which will be found by your python interpreter.
I am creating a Python3 application that depends on a directory of static files in the project.
Project structure:
myBlanky
\__blankys
\__bootstrap
|__google_app_engine
\__my_blanky
\____init__.py
|__my_blanky.py
|__file_system_utils.py
setup.py
MANIFEST.in
README.md
LICENSE
.travis.yml
setup.cfg
So, in my root directory, I have 1 Python module (my_blanky), various Python project files (manifest, setup.py, etc) and 1 directory full of static data (blankys).
I was having troubles creating a .tar.gz package for my application earlier, but after creating a MANIFEST.in file and editing my setup.py file, I was able to create a .tar.gz successfully with command: python3 setup.py sdist.
My setup.py:
from setuptools import setup
from my_blanky import version
setup(name="myBlanky",
...url, author, etc info here...
packages=["my_blanky"],
include_package_data=True,
package_data={'blankys': ['blankys/*']},
zip_safe=False,
entry_points={"console_scripts": ["myblanky = my_blanky.my_blanky:main"]},
install_requires=['docopt==0.6.1'])
My MANIFEST.in:
recursive-include blankys *
include *.md
include LICENSE
include setup.cfg
After I run python3 setup.py sdist, I open up the created .tar.gz file and it includes all the data that I need (blankys directory, my_blanky module, all root dir static files) so it includes all my static files that I need, great.
Then I move onto installing the .tar.gz with pip: find ./dist -iname "*.tar.gz" -print0 | xargs -0 pip install and it runs successfully with no errors. (The output of installing it does not display any information regarding the static files but didn't think it would do that any way.)
Now here is the issue. My python project should now be installed on my machine. I can run myblanky on my machine or myblanky -v and it all works great. Everything runs. But when I try to run any code like myblanky list that tries to access the static files directory "blankys", it breaks saying there is no such directory in /usr/local/lib/python3.4/dist-packages/my_blanky/. I browse to that location manually and the only files there is my Python module my_blanky source files. The parent directory: /usr/local/lib/python3.4/dist-packages/ also does not include any static files at all.
I am expecting the static directory blankys gets copied over to the dist-packages location when I pip install my project. I am expecting the directory to live with my my_blanky module directory so I can use that static files directory my relative path searching in my program.
So if the static files install great into my .tar.gz package and installation seems to succeed on my machine, where are my static files in the installed dist-package? I am installing the project on my machine from the .tar.gz which has the static files/directory in it, so why are those not copied over in the installation? Only the python module my_blanky gets copied over.
UPDATE (2020): For future readers of this question, some people have commented that the original question and answer I gave in 2014 does not make sense or help solve their problem. Sorry, but I have not touched this code since 2014 and I am not able to improve this question or answer. I am leaving it here in case it's helpful, but I am not able to help any further on this.
UPDATE (2020): For future readers of this answer, some people have commented that the original question and answer I gave in 2014 does not make sense or help solve their problem. Sorry, but I have not touched this code since 2014 and I am not able to improve this question or answer. I am leaving it here in case it's helpful, but I am not able to help any further on this.
I feel I have solved this issue.
Essentially my problem is that I have a "settings.config" file that I want to be able to access system wide on the user's machine. So instead of having the settings.config file located in some random directory that my program cannot find, I wanted to have one single settings.config file on the system that it can find and manipulate so I was asking in my question how you go about doing this in distutils.
While I was cleaning out my machine's home directory today I realized that I was going at the idea all wrong. Applications do this idea all the time where it has one config file somewhere in the system it can access. It is located in ~/.config or /etc or on Windows: %APPDATA%. I was asking in my question above how I can install a settings.config file inside of /usr/local/lib/python3 but that is wrong. That is not what I should be doing, just do like what every other program does.
So to answer my question: you can't install a data file in /usr/local/lib/python3 and for good reason. Instead use ~/.config or /etc or %APPDATA%.
I have created my program using virtual env. It is working in my project folder fine. Now i need to take this program and release it to the production environment that is supposed to be accessible by everybody.So this program should be runnable as is or it might be incorporated into other programs as a step. How am i supposed to deploy it? Zip the whole project folder? Is it possible to do without requiring clients to copy it and then unzip and run? Or the only way is to create a commonly accessible script that automates unzipping of the thing and configuring virtual env and then running it or there is a smarter way?
More complicated scenario is when it supposed to be used as library. How to deploy it so others could specify it as their dependency and pick it up? Seems like the only way is to create your own PyPi-like local repository - is that correct?
Thanks!
So here is what i have found:
If we have a project A as API:
create a folder where you will store the wheels (~/wheelhouse)
using pip config specify this folder as one to find links in http://www.pip-installer.org/en/latest/configuration.html
i have:
[global]
[install]
no-index = yes
find-links = /home/users/me/wheelhouse
Make sure the wheel package is installed.
In your project create setup.py file that will allow for the wheel creation and execute
python setup.py bdist_wheel
copy the generated wheel to the wheelhouse so it has:
~/wheelhouse/projectA-0.1-py33-none-any.whl
Now we want to create a project that uses that projectA API - project B
we are creating a separate folder for this project and then create a virtual environment for it.
mkdir projectB; cd projectB
virtualenv projectB_env
source projectB_env/bin/activate
pip install projectA
Now if you run python console in this folder you will be able to import the classes from the projectA! One problem solved!
Now you have finished the development of projectB and you need to run it.
For that purpose I'd recommend to use Pex (twitter.common.python) library. Pex now supports (v0.5.1) wheels lookup as dependencies. I'm feeding it the content of requirements.txt file to resolve dependencies. So as the result you will get the executable lightweight archived virtualenv that will have everything necessary for the project to run.
This should get you started:
http://docs.python.org/2/distutils/
http://guide.python-distribute.org/
http://pythonhosted.org/setuptools/
I am somewhat new to Python and even newer to distutils.
I wanted to create a distribution of my program for other users in my office, so I used setup from distutils.core. I set up my directory structure, created a manifest.in file and a setup.py file. Everything seemed to go as planned. The result is that I have a .zip file containing the directory structure that I intended.
The maifest file was not contained in the .zip file (I assume it was only needed by distutils), but the setup.py file remained in the .zip file. Why is that? Is setup.py needed by the end-user?
Thank you,
-RS
In the normal case, users install your app by running python setup.py install, or something that effectively does the same thing (like pip install foo).
Of course there are cases where they don't need setup.py—e.g., because they're installing a pre-packaged binary egg or Windows installer or whatever—but most packages have to work for the normal case. So, the default packaging commands include it. In the docs, Specifying the files to distribute says:
If you don’t supply an explicit list of files (or instructions on how to generate one), the sdist command puts a minimal default set into the source distribution:
… setup.py (or whatever you called your setup script) …