0

I'm fairly new to Python and even newer to git, so pleas forgive me if I'm going over old ground, but I need the assistance of an expert:

I am working on a python(3.4) project of my own which makes use of a library I installed using pip. This library is also available as a repo at python-OBD. I have needed to make changes to this library, and given my limited knowledge, I've made changes directly in the installed code (/usr/local/lib/python3.4/dist-packages/obd/...), which I have not doubt is probably the most wrong way of doing it, so...

What would be the best way of achieving this the right way? If I pull the repo, where would be the best place to put it (my project is located in /home/python/obdlogger/). Would it be beneficial to pull the repo to /home/python/obd for example? Then, how do I make reference to that library in my own project? As the library is installed via pip, at the moment I just

import OBD

but I'd be guessing that this would no longer be sufficient to reference the repo I've pulled. Lastly, should I uninstall the library installed via pip to avoid python confusion?

Hope this makes sense! Any help would be appreciated.

1 Answer 1

1

The most common way is to create a virtualenv, and do an editable install of OBD in there:

# Create virtualenv
virtualenv myproj
cd myproj
source bin/activate

# Clone all libraries you want to change
git clone your-library
git clone https://github.com/brendan-w/python-OBD.git

# Install cloned libraries
pip install -e python-ODB
pip install -e your-library  # all dependencies except python-OBD will be installed, too

Both python-OBD and your-library will be installed in place, which means afterwards you can change both libraries to your needs and every time you do

import OBD

anywhere in the virtualenv you will import the code you cloned and changed.

Sign up to request clarification or add additional context in comments.

3 Comments

I am quite new to stackoverflow and noticed that my answers are often downvoted when another answer is provided later on. Is it common here to downvote the other answers if you give one yourself? I can't currently counter such behavior with the same measure because of not enough reputation points ... Is this a kind of reputation wars?
No, I just objectively disagree with your suggestion to edit sys.path or use absolute path imports.
Thank you Nils. Just what I was looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.