Python 3 Project Initialization / Prototyping - python

I'm looking for the correct way to prototype, initiate a Python project.
PasteScript has not been updated to Python 3.
Skeleton is available fror 3.1 but has not been maintained for the last two years.
Step by Step Guide gives information to manually create the structure of a project for packaging.
The Hitchhiker’s Guide to Packaging
Is there any new candidate for starting a project and populating all the files necessary for the project?

Not exactly what I was looking for but it will do the job.
A Project Skeleton
Another project skeleton to download on Github.
How to Package your Python Code
Adding new information
Cookiecutter seems exactly what it requires to initialize and start a project. See a blog posts explaining it.
Cookiecutter for libraries

Related

Python: How to create dependencies in repos in python projects?

I am a python beginner, I have Project One which has all the code in a git repo, I am starting a few new projects with their own repos which will all use the generic code in Project One, I don't want to copy paste code. What I am hoping to achieve is separate out the generic code from Project One so it can be inherited/imported in different projects.
generic_Code
-fileOne.py
-fileTwo.py
repo two
Project One
-fileA.py
-fileB.py
repo three
ProjectTwo
-fileC.py
-fileD.py
The goal is I should be able to import classes from Generic_Code repo into files in project one and two. I am using Pycharm and a mac system. On Pycharm, I attached the three projects together and made projectone and two have dependencies to the Generic project, which seem to work but not sure if this is the right way.
Also read something about setup.py but not sure what that is.

Navigating through Github repos

I am currently trying to find end-to-end speech recognition solutions to implement in python (I am a data science student btw). I have searched for projects on github and find it very hard to comprehend how these repositories work and how I can use them for my own project.
I am mainly confused with the following:
how do repositories usually get used by other developers and how can I use them best for my specific issue?
How do I know if the proposed solution is working in python?
What is the usual process in installing the project from the repo?
Sorry for the newbie question but I am fairly new to this.
Thank you
how do repositories usually get used by other developers and how can I use them best for my specific issue?
The best way to get started with GitHub is to review the documentation.
How do I know if the proposed solution is working in python?
Every repository includes a monochrome / colorful line between the caption and the code section. On clicking this line, you can see the languages of the current project (here is the example for Tensorflow)
What is the usual process in installing the project from the repo?
Usually the project installation and usage steps are described in README.md file that should be attached to GitHub repository. This assumes installed git and basic knowledge of its commands.
You can read the documentation(README.md) there you can have all the information you need.
You can install the project from a repo by cloning or by downloading zip.

Getting started with django-restframework-gis on Windows 10

I have some experience with Python-Django including its REST framework, a reasonable understanding of geographic information (and what GIS is about) and about databases, and I would like to develop a "geo-aware" REST service on my Windows machine based on Django. The application shall be limited to the REST service; visual exploration and other stuff shall be developed independently. Side-remark: once my application is running, it will be ported onto a Linux machine and PostGIS will then be used instead of SpatialLite.
After several hours of web-searching, I still haven't come up with a good "Quickstart" guide. There are many tutorials and docs about various aspects related to my task, but they either refer to Linux, or their installation instructions are outdated. Here is what I have done so far:
1) I use miniconda and Pycharm
2) I created a new virtual environment like so:
conda create -n locations pip numpy requests
activate locations
conda install -c conda-forge django djangorestframework djangorestframework-gis
3) I set-up the new Django project and my application and performed a database migration:
python [path-to..]\django-admin.py startproject locations
cd locations
python [path-to..]\django-admin.py startapp myapp
cd ..
python manage.py migrate
4) I added "rest_framework" and "myapp.apps.MyAppConfig" to the APPLICATIONS in settings.py
5) I stopped reading the general django-restframework tutorial and began searching for django-restframework-gis specific information. What I understood from this is that I need to enhance my SQLite database to become a SpatialLite database. Windows binaries for SpatialLite are available at gaia-sins -- but which of these do I really need? I downloaded the mod_spatialite-4.3.0a-win-x86.7z file and unpacked it, and I added SPATIALITE_LIBRARY_PATH= '[path-to..]\mod_spatialite-4.3.0a-win-x86\mod_spatialite.dll' to my settings.py.
What comes next?
Specific questions:
1) Do I really need to upgrade my SQLite database if I am not planning to store geospatial information but merely build a REST service to deliver information in GeoJSON which is coming from other sources (for example weather model output in netcdf data format)? Or would it suffice to describe my Django model in this case and simply ignore any database-related issues?
2) What is the minimum code to get the basic "wiring" done? This could be an extremely simple service which would accept a lat/lon coordinate as parameter in the URL and return this location in GeoJSON format. Such code should highlight the differences between using the "normal" django-restframework from the gis version. Once I have this, I will probably find my way through the existing documentation (for example Miguel Grinberg Tutorial or GitHub description).
OK, after another day of searching and experimenting, I acknowledge that this has been the wrong question to ask - therefore I answer myself and close this issue.
Apparently, I have been to naive about setting up a "geo-aware" service, thinking that I can get away with a special datatype or two for coordinates, and a special kind of serializer for GeoJSON - and, if really necessary, with a geo-enabled database.
Turns out, that what I want to do in the end, is a GeoDjango application (even if I will use only a tiny fraction of what GeoDjango can do), and so the GeoDjango docs are the place to start from, and in particular their installation guide.
The story isn't over yet as I am still having troubles to load the required libraries from Django, but the direction is clearer now.
More specifically, the issue I ran into wasn't primarily a SpatiaLite issue. I was able to install SpatiaLite and enhance an existing sqlite database by running SELECT load_extension('mod_spatialite'); SELECT InitSpatialMetaData(); (see also this post. Django (python manage.py check) complained about not finding the gdal library, and once it found it, it was the wrong version. The GeoDjango docs report that this is indeed the most common problem when installing GeoDjango. It would be helpful if the error messages from ctypes were a bit more verbose to make it easier to search for solutions. It took several hops across various web sites and an extra print statement in the ctypes init.py file, before I found out that one needs to match the version of gdal, the version of python, and the compiler (DLL hell this was called by someone).
Another part of the confusion arises from the manifold dependencies among the various required "geo packages". For example, SpatiaLite already comes with a gdal library, so why the need for installing gdal separately? Indeed, the GeoDjango docs recommend to work with OSGEO4W, because this program suite bundles everything together. Yet, this is not trivial if one starts from a system where OSGEO4W and Python/Django have been installed independently. This is the situation I start from. I installed OSGEO4W primarily to work with QGIS, and I installed Python and Django for other tasks. The realisation that the two must be linked for a GeoDjango application only came afterwards. I might need to start from scratch, but it would be good to know if people have been successful in a Windows 10, x64 environment with Python >= 3.4 recently.

How do I download a 3rd party python module and integrate it with my python

I would like to be able to use the services that the Blockcypher module provides for my programme, however i have (at least i think) downloaded the correct module package but cant get it to integrate with my Python on my Computer. I am fairly new to python so I have no idea on where to even start tackling this problem.
Modules, regardless of where you've got hold of them, will be searched for in the sys.path. If nothing is found there, they will be looked up in the current directory.
When you download some code directly it will be a good first guess to place it in the directory of the script from where you are using the download. If it's just a .py-file, place it there. If it's an archive with a directory, then place the directory there (not the files).
Generally, you should prefer installing modules via a package manager such as pip or conda. Such package managers take care of placing modules properly for usage with your Python installation from wherever you will write your script. They also provide support for updating these modules to newer versions later.
Update: If you cannot make anything from this remarks, you should first read the section on modules in the Python tutorial, or even work thru the full tutorial or thru a good book (or any other ;) to get a smooth entry into the friendly world of Python programming.
Update (2023): The Dive Into Python link above is outdated, so here is the updated link to this great resource:
https://diveintopython3.problemsolving.io
I think it's still the best beginner's resource, but, well, here are many more:
https://wiki.python.org/moin/IntroductoryBooks

PyCharm include and modify External library in project

I have an issue where I am developing a Django project which includes other libraries we are also developing.
My current structure is as follows:
Main Project
App1
App2
Libraries
Library 1
Library 2
All libraries have their own setup scripts and are in separate git repositories, and we are adding them in PyCharm in the PYTHONPATH, and referencing them simply by their name. Which works good, but they are not in my current project, which means no re-factoring ( renaming, moving etc... ) and I have to use External search to find my class from the libraries.
How do I set some libraries as project related to make them view-able and refactorable like we do on the currently set project.
Well, you can add other directories as content roots:
Then simply mark the directory as a source root:
This should allow you to refactor, rename and do all the things you've wanted to do.
Another option would be to place libraries into separate project (or go even further and place each library in its own project) and then open this project/these projects side-by-side with the main project. This way you have clear separation between the main project and libraries used. This comes handy when you work on another project using some of the same libraries as then you only need to open already existing project containing libraries and you are done.

Categories