Continue developing an already installed application - python

I recently wrote my first setup.py (with distutils) for an application I'm working on. This installed the library in /usr/local/lib/python and the executable script in /usr/local/bin. This is great, except I want to continue working on it, and whenever I call my application it first looks in /usr/local and runs it from there, instead of the directory I'm at. So I have to manually go and delete the files form these locations. What is the proper way to do this?

If you've got it all packaged up you should be able to say
python setup.py develop
and it will install it locally for you to test.
Then, if you want to uninstall it just
pip uninstall my_package

Related

Running a python application from source file without using pip install

There is an application where I downloaded the source code and would like to modify it.
https://github.com/ownaginatious/fbchat-archive-parser
Is there a way to run this program by entered a command such as "python3 main.py" rather than installing the program. When the program is installed, I would simply run the command fbcap.
This project has a setup.py file. The "standard" way to run such a thing is to install it (preferably inside a virtualenv) and then run it. Virtualenvs are cheap and lightweight so it's easy to do.
First, create a virtualenv. This might be slightly different depending on your platform. I presume you're using Python 3 so these instructions should work for you. Let's assume you created it in /tmp/venv1
Activate it using . /tmp/venv1/bin/activate (don't forget the initial .). This also might be different if you're on Windows.
Now install your program using python setup.py install.
Run it using fbcap.
This will allow you to run the program in a clean fresh python environment and when you're done experimenting, you can simply delete the virtualenv directory.

How to get Django classifieds running on my local server

I am starting on a project for classified ad listing site and found a template to get me started.
The installation instruction on git are not clear to me.
I created virtual env and installed dependencies using pip but I can't finish the installation process: manage.py runserver could not be executed and showed "could not find module sorl.thumbnail".
I think there is some error due to folder structure but cannot figure out what. Any ideas?
This is my folder structure.
It seems that the dependency sorl.thumbnail is not (successfully) installed.
Try running pip install sorl-thumbnail==11.05.2. That should install the module (in the version required by django-classifieds according to the requirements.txt). Check the output for any errors.
Also, make sure that you are using the right environment.
My only guess is that you either forgot to install sorl.thumbnail or that it is in a separate environment than django-classifieds. To add it manually, download the zip from the specified URL, extract the zip, and, in a command prompt/terminal in the directory you extracted the zip into, and run python setup.py build and python setup.py install.

Why does easy install want access to my rootfs for a "develop" install?

I'm looking at a python application server and I wanted to play around with the code. I'm lead to believe passing "develop" to setup.py should leave everything in place without installing anything. However when running so it is attempting to creating directories in my rootfs.
./setup.py develop
Gives:
running develop
Checking .pth file support in /usr/local/lib/python2.7/dist-packages/
error: can't create or remove files in install directory
I thought this might be something to do with package checking but surely attempting to write stuff into the rootfs is wrong?
The develop command wants to add a .pth entry for your project so that it can be imported as an egg. See the Development mode documentation, as well as the develop command docs.
The default is to put that entry in site-packages. Set a different library path with the --install-dir switch.
You can use --user option (Alternate installation: the user scheme).

Developing Python Module

I'd like to start developing an existing Python module. It has a source folder and the setup.py script to build and install it. The build script just copies the source files since they're all python scripts.
Currently, I have put the source folder under version control and whenever I make a change I re-build and re-install. This seems a little slow, and it doesn't settle well with me to "commit" my changes to my python install each time I make a modification. How can I cause my import statement to redirect to my development directory?
Use a virtualenv and use python setup.py develop to link your module to the virtual Python environment. This will make your project's Python packages/modules show up on the sys.path without having to run install.
Example:
% virtualenv ~/virtenv
% . ~/virtenv/bin/activate
(virtenv)% cd ~/myproject
(virtenv)% python setup.py develop
Virtualenv was already mentioned.
And as your files are already under version control you could go one step further and use Pip to install your repo (or a specific branch or tag) into your working environment.
See the docs for Pip's editable option:
-e VCS+REPOS_URL[#REV]#egg=PACKAGE, --editable=VCS+REPOS_URL[#REV]#egg=PACKAGE
Install a package directly from a checkout. Source
will be checked out into src/PACKAGE (lower-case) and
installed in-place (using setup.py develop).
Now you can work on the files that pip automatically checked out for you and when you feel like it, you commit your stuff and push it back to the originating repository.
To get a good, general overview concerning Pip and Virtualenv see this post: http://www.saltycrane.com/blog/2009/05/notes-using-pip-and-virtualenv-django
Install the distrubute package then use the developer mode. Just use python setup.py develop --user and that will place path pointers in your user dir location to your workspace.
Change the PYTHONPATH to your source directory. A good idea is to work with an IDE like ECLIPSE that overrides the default PYTHONPATH.

Trouble installing Django

I'm having trouble installing Django, even if I follow the instructions here: http://www.djangobook.com/en/2.0/chapter02/
Could someone please provide baby steps to installing Django. I'm talking baby steps that really break it down, so that a retarded person could do it.
I've installed Django and unzipped the file, but I'm unsure where to go from there.
I on Windows 7, and I've downloaded Python 2.7 and Django 1.2.1.
OK. If you have Python installed, you can then proceed to execute setup.py given with Django. Head over to the directory where you unzipped Django.
cd C:\path\to\Django\
You can now execute
python setup.py install
This step requires your python executable to be present in the system's PATH environment variable. If it isn't you will have to append your Python installation directory to your PATH.
Update
You can verify that the installation has gone well with the following command. Run python and execute the command import django. If no import errors are thrown everything is OK. Thanks to cji for the tip.

Categories