install python package from github using requirements.txt - python-3.x

Whats the successful way to import packages from github repo?
Here is what I tried
Tried Installing a python package- corepkg, which is available in git repository - git.example.com/corepkg.git
In another Project- Proj2, to import logic from above corepkg package, Kept an entry in requirements.txt and ran the following pip command.
pip install -r requirements.txt
Here are my Entries in requirement.txt for Proj2
...
PyYAML==3.12
requests==2.18.4
urllib3==1.22
git+https://git.example.com/corepkg.git#develop
But it did not create any src folder or .dist-info folder in virtual environment site-packages?
It just created corepkg-1-py3.6.egg_info file but not files required to import.
Whats the step I am missing here to import it successfully from git?

Try
git+https://git.example.com/corepkg.git#develop#egg=corepkg
See https://pip.readthedocs.io/en/stable/reference/pip_install/#vcs-support
The problem also could be in the very corepkg.git repo so it's hard to say something without looking at the repo.

Related

I have completely messed up my Python Env and need help to start fresh

Long story short, I messed with my Python environment too much (moving files around, creating new folders, trying to reinstall packages, deleting files etc.) My google package doesn't work anymore. Everytime I try to import the package, it says it can't find the module, even though I did a pip install.
I was wondering how I could do a hard reset/delete python off my computer and reinstall it.
Thanks.
is your pip working try extracting the required modules.
pip freeze > requirements.txt
create new Venv
pip install -r requirements.txt
I figured it out. My pip was installing to a site packages folder inside a local folder, while my jupyter notebook was trying to pull from the anaconda site packages folder.

ifxpy module cannot be installed using pip

i am trying to install this a flask project on another server but later realized it was failing at ifxpy during the
pip install -r requirements
The github link for the project is https://github.com/OpenInformix/IfxPy. Is there a way i can install it from the github repository.

Figure out in setup.py what repository this package is being installed from?

Say I have a python package blah
I can install it in two ways:
pip install git+https://github.com/blah/blah.git#blah (using github repo)
and
pip install blah (using pypi repo)
Is there a way to figure out which of the way the user is installing the package in setup.py ?
So that I can essentially do something like:
if INSTALLING_FROM_PYPI:
# some logic
if INSTALLING_FROM_SOMEWHERE_ELSE:
# some other logic
Just include a file in your Git repository:
$ touch .git-flag
Explicitly exclude it from your distribution in your MANIFEST.in file:
exclude .git-flag
Then in setup.py, check for the existence of that file relative to your setup.py file:
import os
this_dir, this_filename = os.path.split(__file__)
path_to_flag = os.path.join(this_dir, ".git-flag")
installed_from_git = os.path.exists(path_to_flag)

Python 3 - How do you re-create your Pipfile?

I am a major Python noob, and I made the mistake of manually deleting my Pipfile and Pipfile.lock, thinking that they would eventually regenerate.
How can I re-create these files?
There is a simple fix to this:
First you need to install pipenv if you haven't already:
pip install pipenv
Then change directory to the folder containing your Python project and initiate Pipenv (replace my_project with the name of your project folder):
cd my_project
pipenv install
This will create two new files, Pipfile and Pipfile.lock, in your project directory, and a new virtual environment for your project if it doesn’t exist already.
For regular pip:
pip freeze > requirements.txt
For pipenv:
pipenv run pip freeze > requirements.txt
And to install:
pip install requirements.txt
Situation: you have deleted Pipfile and Pipfile.lock, but your pipenv environment is still there. By this I mean pipenv shell puts you in your environment with a python that has all your packages right there.
# Create a new Pipfile
pipenv install
# Get a list of your packages + version from the would-be "reqiurements.txt", then install them one by one.
pipenv run pip freeze|sed 's/^/pipenv install /'|source /dev/stdin
Note that this is not a perfect solution, as it will specify the versions in the production target environment as you would get from pip freeze i.e. requirements.txt. However this has saved me more than once, so I hope it helps you.

Save all currently installed packages in anaconda to a file

I want to make a .txt file with all the python packages my environment is using, and include it in the git repo, so that anyone who needs to run the code, can just make an environment, install all the packages from the list and use it.
I have two questions, first, how can I create that .txt files with all the installed packages? Second, how can someone with the .txt file install everything from it (using pip3?) in their fresh anaconda environment?
After activating your environment, you can do this:
pip freeze > requirements.txt
And to install all these packages in a fresh environment:
pip install -r requirements.txt
Hope this helps!

Resources