Download this app from Microsoft Store for Windows 10, Windows 10 Mobile, Windows 10 Team (Surface Hub). See screenshots, read the latest customer reviews, and compare ratings for Movie Creator: Free Video Editor.
I want to create a 'library' of Python modules which I will be able to access from several separate project folders.
For example, I want the Python scripts in /proj1/ and /proj2/ to have access to /lib/.
I don't want a single directory with all the Python scripts, as this seems rather disorganized. I also definitely don't want to copy the same /lib/ script into each of the different projects.
What is the ideal way to handle this in Python? Is it appending to Python's path? Or is this more of a hack? This seems to have the disadvantage of making the files less portable. Or is it this question/answer about using relative paths? Or something else?
I should add that I'm interested in Python 2.x rather than 3.x, if it matters.
Community♦
David CDavid C4,63322 gold badges4141 silver badges5959 bronze badges
3 Answers
Turn
Ignacio Vazquez-AbramsIgnacio Vazquez-Abramslib/
into a package, then put it in one of the directories in sys.path
(or add a new entry). You can then import e.g. lib.help
into your projects.603k109109 gold badges11001100 silver badges11911191 bronze badges
Follow the standard road that everyone takes: make your code a proper Python package with a proper setup.py. The benefits are: easy_install'able, easy distributable, easy generation of command line script (through console_scripts entry point) etc....
Andreas JungAndreas Jung
I think the best tool you can use to keep under control the environment of your project is virtualenv. You create a new virtual environment and install there your packages, then you run your project using the python executable that virtualenv provides you.
Probably you should use distutils in your library, in this way installing it with virtualenv is really easy, because virtualenv installs setuptools or distribute in the virtual environment, thus allowing you to install in the virtual environment packages from pypi or from your local machine.
There is also the possibility to create a custom bootstrap script that automatically installs some libraries after the virtual environment creation.
BakuriuBakuriu69k1212 gold badges144144 silver badges174174 bronze badges
Not the answer you're looking for? Browse other questions tagged pythonpython-2.x or ask your own question.
Libraries gather folders that are stored in different locations so you can browse them in one place. You can add or remove folders and drives to be included in a library as you like.
This tutorial will show you how to create a new library for your account in Windows 10.
This tutorial will show you how to create a new library for your account in Windows 10.
CONTENTS:
- Option One: To Create New Library using New Context Menu
- Option Two: To Create New Library using File Explorer Ribbon
- Option Three: To Create New Library using 'Include in Library' Context Menu
To Create New Library using New Context Menu
1. Open Libraries in File Explorer.
2. Right click or press and hold on an empty area in the Libraries window, click/tap on New, and click/tap on Library. (see screenshot below)
3. Type a name you want for the new library. (see screenshot below)
4. You will now be able to include folders to the new library. (see screenshot below)
To Create New Library using File Explorer Ribbon
1. Open Libraries in File Explorer.
2. Click/tap on the Home tab, click/tap on New item in the ribbon, and click/tap on Library. (see screenshot below)
3. Type a name you want for the new library. (see screenshot below)
4. You will now be able to include folders to the new library. (see screenshot below)
To Create New Library using 'Include in Library' Context Menu
1. Open File Explorer, and browse to the folder you want to include in a new library.
2. Right click or press and hold on the folder, click/tap on Include in library, and click/tap on Create a new library. (see screenshot below)
3. A new library will be created with the folder
included, and the new library will be named the same as the included folder.
If you like, you can rename the new library anything you like.
You will also be able to include more folders to the new library.
You will also be able to include more folders to the new library.
That's it,
Shawn