I have a file mysql.py
, which I use in almost all of my projects. Since I do not want to copy and paste the same file into each of these projects I wrote a module - possibly a package in the future.
Question
How do I add a local module to my conda environment, and automatically update or watch it when I change something in mysql.py
? How to do the same for a package?
I would like to avoid to set up a local channel/repository and just reference to the folder with mysql.py
.
If you install the conda build package (and you have a package, not just a script), you can install in "editable" mode:
(running from the directory with your script). This is very similar to the "editable" mode from pip
Either approach lets you uninstall packages with either
or
If you just have a script (not a package), you can edit or set the
PYTHONPATH
environment variable to include the directory with the script.I had a wrapper function that I had to call multiple times on different scripts.So, I copied that file
wrappers.py
to the Anaconda site-packages folder. On my computer this was at: C:\ProgramData\Anaconda3\Lib\site-packages. Then, whenever I neededwrappers.py
, I'd just import it in my scripts, like this:If you want to make sure that the import was successful, you could either select Anaconda as your dev environment in your IDE and then invoke the Intellisense after import:
from wrappers import (intellisense suggestions)
. Or you could also use IDLE:Conda integration is only possible if you create custom channels. This is because conda searches for packages in the following locations(based on your OS) and to tell conda to search for your module at certain location(s), you must install
conda-build
to create a custom channel:If you want to avoid creating a repo/channel, then a simple import as above should do the job. In addition, if you make any changes to your module and save it, you will always have the latest
import
in your scripts.While the previous answers are doing what I need, I just want to show what I will be using instead. Since it was my plan to learn about conda packages anyway...
0. Good sources
1. Create a python package template for conda using cookiecutter
Now change to the directory where you want to initialize your package, then do:
This will ask for some basic information about the package that you want to create. Then change into your repo
2. Build your package
make sure
conda-build
is installed, if not runMake sure to set the
CONDA_BLD_PATH
as mentioned in anaconda - using a different conda-build root directory - Stack Overflow. This will be the directory where you can find your packages, then run:to build your package and clean up after you with
3. Set up your own local channel (no uploading to anaconda.org)
Read
for help.
Index each platform. Maybe someone can confirm that this step is not needed, as my builds already contain the
repodata.json
. Otherwise:Test if the package can be found with
or add the channel to the config directly (per environment)
4. Install (and update) the package
and
Once I change
mypackage
, I give it a new version number inmeta.yaml
andsetup.py
and build the package withconda build conda.recipe
. Updating is simplySee if your package works:
This may not be the optimal way, but I could not find a tutorial that contains all the steps I outlined above.