2

When I install a python module using pip -t . pip downloads the module into a specific folder in the current directory. Python then searches the current directory for the module when it is imported and all is well.

What is the best practise for whether to add the module folders into GIT?

It seems to me that checking in these folders is not a good idea, instead the build process should download them from the requirements file rather than get them from SCM.

However adding each folder into .gitignore seems overly burdensome.

I was expecting the python modules to go into some special directory such as python_modules which I could then add to .gitignore however this does not appear to be the case. Or is there some kind of hook that I can use to get pip to update the .gitignore file automatically when installing new modules?

So what do people do to manage these files? My googling has so far not revealed much and I am not at a loss as to what to do?

2
  • 1
    If your project is an application and not a library, consider using a virtual environment to manage your dependencies. Pipenv works well for me. Commented Aug 27, 2019 at 15:56
  • It sounds like you're trying to do something akin to using a virtual environment. I would suggest using conda. Commented Aug 27, 2019 at 15:56

1 Answer 1

2

One option would be to create a directory called python_modules, and then when you install a new module, install it with pip install -t python_modules .... This way you can add python_modules to your .gitignore.

That being said, what's your rationale behind installing them inside your project rather than letting the build process install them in the usual location on your system?

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

3 Comments

It comes from writing python Lambda functions where you have to import modules. Are you suggesting that I should not specify the target option and just let Pip install to a system location? I am really just looking for best practise advice.
yeah, that's what I'm suggesting. I can't think of a valid reason to require the packages to be installed in your project directory rather than the system location
I guess i was expecting Python to work the same way as npm does when adding modules which makes updating gitignore super easy since everything module is contained within the same parent directory. If I were to use a target of python_modules how would you tell Python to look into those directories when importing modules?

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.