I want to customize a python package. I need to be able to install the customized package in anaconda on other machines. This is the method by which i'm installing the customized package in case it's relevant: How do I install packages to Anaconda from locally built tar.gz
However i would also like to rename the package. For example if i wanted to edit openpyxl, i want my edited package to be called openpyxl_edit. However the name openpyxl is used in multiple places throughout the original package source code.
Is it likely that i have to rename openpyxl to openpyxl_edit in all of the occurrences in all of the source files in the entire package? Is there an easier way of changing the name of a package?
Related
I need to make some changes to the way the OSMnx package gets data from the Overpass API.
To do that, I've forked the repo and cloned that fork into a local directory.
I've made a simple change, adding a print functions to start.
I'm trying to figure out the steps for installing and importing the modified version of the package. I've looked at this question
I'm concerned about a namespace conflict, should I change the name of the folder or the name value in the setup.pyfile. I don't want to write over the working version of the package
What file should I point to when installing? setup.py, core.py, _init_.py?
I haven't found any tutorials on how to modify an existing package safely, just stuff on how to make a package from scratch.
import will search the installed packages list first, then it will check the directory it was called from for files that match the package it's looking for.
So either using pip or conda remove the original version of the package being imported.
Then, be sure that the modified version of the package that you want to import is in a sibdirectory of your project directory, and run import package as xx and it should load the modified package files.
If it doesn't, it's likely that the package wasn't removed from the right environment.
Why we have to install the python packages before using them?
I am currently working on a small python mysql program. What i tried to download the python connector module from mysql webpage and simply unzip it and place it in the same folder of my code.
And I can import the module properly.
So what is the meaning of installing those packages? Can I use those packages like matplotlib, numpy without installing them ?
Is it possible to have all the required packages installed on a folder so that i can move it to another computer and run my program with only CPython installed (I don't want to install any package on this computer)?
it's not that simple :-)
some packages have dependencies, you also need to download and extract their dependencies (you need pacakge x,and package x uses y) pakcage manager handles that
some package have some c code (they need to be compiled before use (ujson or postgres module) package manager handles that
when your share your code instead of sharing dependencies you simply add a file containing the list of dependencies (requirements.txt) and other user can simply install all dependencies using package manager
Installing a python package enables us to use it anywhere on our system. If we just place the package in the same directory as our script then it may well work, but only for scripts in that directory.
Some packages also rely on others to function properly, and the installation of a package may well install those pre-requisite packages for you. You may be able to do this manually, but you'd have to put them all in the same directory as your script every time you wanted to run it.
So installing the packages is the easiest way to use them.
You don't have to install them, and in some cases you wouldn't install them on your system; if you had split your code across two files and imported one file at the top of the other for example.
In fact, you don't really need install package on your system.
But if you install it, you can use these packages every where on your system.
Also, you can create a requirement.txt file to enable install all packages that you need on other computer. You can check this manual https://pip.pypa.io/en/stable/user_guide/#requirements-files
I have a general question using third party libraries, but I will exemplify it on two examples to make it clearer and more "answerable":
I want to use pyfmi in Python. Trying to install it through pip tells me:
"Exception: FMI Library cannot be found. Please specify its location, either using the flag to the setup script '--fmil-home' or specify it using the environment variable FMIL_HOME."
I figured out that I had to download the tar.gz from jmodelica.org and extract the files, create a build directory, use cmake, make and make install commands. All runs through without a hitch. But trying to install through pip gives me the same error message. So my question is:
How does one do this? Do they mean by setup script the setup.py file? How can I access that one if I am installing through pip?
An which one is the fmi home directory? Is it the untarred file in my Downloads-Folder or one of the files in it:
builddir
Config.cmake
install
src
Test
ThirdParty
CMakeLists.txt
FMILIB_Acknowledgements.txt
FMILIB_License.txt
FMILIB_Readme.txt
LICENSE.md
README.md
? What is that flag and where to put it "exactly".
Thanks a lot.
PyFMI requires (as noted on the PyPI site) that FMI Library is installed prior to trying to install PyFMI from source.
During the installation (invoking python setup.py install) of PyFMI, the environment variable "FMIL_HOME" is checked to see if that points to an installation of FMI Library, if so, this will be used during the installation. So in your case, you need to set this environment variable. The other option is to install manually (using python setup.py install --fmil-home="/path/to/fmil") where the added path should point to FMI Library.
The third option is to see if there are binary installers for your platform (these include FMIL). Check PyPI, Anaconda and Christoph Gohlke's site.
A Python module is just a .py source file. A Python package is simply a collection of modules.
So why do we need programs such as pip to 'install' Python modules? Why not just download the files, put them in our project's folder and import them?
What exactly does it mean to 'install' a module or a package? And what exactly does pip do?
Are things different on Windows and on Linux?
So why do we need programs such as pip to 'install' Python modules? Why not just download the files, put them in our project's folder and import them?
It's just meant to facilitate the installation of softwares without having to bundle all the dependencies nor ask the user to download the files.
You can type pip install mysoftware and that will also install the required dependencies. You can also upgrade a software easily.
What exactly does it mean to 'install' a module or a package? And what exactly does pip do?
It will copy the files in a directory that is in your Python path. This way you will be able to import the package without having to copy the directory in your project.
With your proposal, for each and every project you have to download the required modules as dependencies. You have to download them again and again and add them with your project which is not very suitable though some platform like node.us do it.
What pip do is to keep the modules you installed in /use/lib/python*/site-packages/ so clearly it is included in your Python's path. So, when you try to import a module or package it checks in site-package if it exists. If exists,then this code will be used with your project. If not, you will get an error.
Lets imagine I created new module. Why do I need to install it via setup file? I mean I can just add my module to PYTHONPATH variable and thats all. Thanks
For a simple one-file module, sure, that's enough.
But a setup.py file also lets you create a distribution, associate metadata with the distribution (author, homepage, description, etc.), register your package with the Python Package Index and most of all, lets you define what other packages might be needed to run your code. setup.py is not just for installing your module.
Installing a module with a setup.py based on setuptools also gives you additional functionality, such as support for namespaced packages (multiple distributions sharing a top-level name) and the ability to install multiple versions of a package side by side.