Not able to clone repository through gitpython - python

I am trying to clone a gerrit project onto my local machine through gitpython which I installed through the following command.
pip install gitpython
I have a python script with the following code.
#git.py
import git
git.Git().clone("ssh://user#host_ip:port/proj1")
This is not giving me the expected result. It gives me the following error.
AttributeError: 'module' object has no attribute 'Git'
I can run just git clone ssh://user#host_ip:port/proj1, which works perfectly fine and gives me a cloned repository but not through the script.
Also, after installing gitpython, the first time I enter python command shell, import git does not give any error. But, if I do the the same after running the git.py script mentioned above, I get the same error AttributeError: 'module' object has no attribute 'Git'.
I don't know where I am going wrong and would like some guidance.

As your file is called git.py, it is imported when import git is executed. You need to rename it.

I guess that code you use was for a different git library. Take a look at their documentation, i guess something like this should do the trick:
import git
git.Repo.clone_from(url, path)
I didn't actually tested it but anyway I hope this helps!

Related

Importing module from Github to use in Python

I'm a beginner in Python and I have no experience with GitHub at all. I want to import the module semsimlib from the following URL: https://github.com/timvdc/semsimlib
I have looked on the internet for help on how to do this but most of it is very unclear and doesn't seem to work for me. Can anyone provide a detailed explanation on how to do this in a easy way?
It looks the repo does not provide appropriate scripts to simply install the package. There is no setup.py file and there is no distribution on pypi.
What you can do is go to site-packages folder inside your python installation or inside your virtual environment. Then run git clone https://github.com/timvdc/semsimlib. You should now be able to import semsimlib. Keep in mind that you will also have to install all the other dependencies your self one by one since there is also no requirements file.
You can also clone the repo into any folder on your computer and at the top of your script put:
import sys
sys.path.append("path/to/semsimlib/folder")
semsimlib will now be importable. However, I would try to get it to work with the first method.

Can you install a python file from git as a module?

I am currently interested in installing the following git repository:
https://github.com/CodeReclaimers/neat-python/tree/master/examples/xor.
It contains a file called visualize.py and I would love to just install and use it as a module (e.g. numpy). However, I'm not sure how if it is possible to do this and was, therefore, hoping anyone could clarify this for me.
I have tried:
pip install git+https://github.com/CodeReclaimers/neat-python/tree/master/examples/xor
Any help would be appreciated!
Edit:
I was able to clone the entire repo:
pip install git+https://github.com/CodeReclaimers/neat-python.git
Does this mean I should be able to use all the files available in this repository as a module or is there something I'm still missing? I still cannot use visualize as a module. Thanks!
If you are able to clone the library to the same directory, you can simply import the python file without pip installing as module.
For instance if the file is called myFile.py, you can call the following and the entire file is executed and functions within can be used.
import myFile
1- open directory with modules
example : c:\users\james\appdata\local\programs\python\python39\lib
2-New python file created
example : visualize.py
3- save the python file.

How to fix `AttributeError: module 'apache_beam.coders.coders' has no attribute 'VarIntCoder'`

I am working on building an Apache Beam pipeline but I am running into an AttributeError when attempting to import pipeline options.
I am testing on an Ubuntu server in a clean virtual environment using python3.6
Steps:
virtualenv -p python3.6 beam-env
. beam-env/bin/activate
pip install apache_beam==2.12.0
python3.6 test.py
Inside test.py:
from apache_beam.options.pipeline_options import PipelineOptions
I would expect the import to work successfully but I am getting the following error:
AttributeError: module 'apache_beam.coders.coders' has no attribute 'VarIntCoder'
I discovered one very weird behavior while writing my own data pipeline with apache-beam: You get this behavior as soon as you have a pipeline in a file called test.py.
Let's say you have your current implementation in main.py, you only need to copy the whole code into test.py file and after that it will produce the error on both files.
The only way for me to fix this right now is to either delete that test.py or rename it to some other names and the problem's gone.
For those using Google Colab I had the same error and solved it by restarting the runtime and running the whole notebook again.
My imports are
!{'pip install apache-beam[gcp]'}
!{'pip install apache-beam[interactive]'}
!{('pip install google-apitools')}
Update:
In fact the error is due to python3. Switch to python2.7, the error is gone. Beam is transiting completely to python3, which is expected to 100% finish very soon. [I am not sure about a ETA for 100%, maybe double check in user group for an exact time line]
Original:
Do following as well in your virtualenv:
pip install -e .[gcp,test]
and maybe also do this under apache_beam folder:
python setup.py sdist
And then try again.
Setup environment could be tricky even if a virtualenv is used. I sometimes find the tips in this page useful: https://cwiki.apache.org/confluence/display/BEAM/Python+Tips
Hope it helps.
In order to fix this error, you can open a new project. Then, reinstall apace-beam.

GitPython - clone_from not working

I am facing an issue while cloning a git repo.
I am using function clone_from from GitPython library
from git import Repo
Repo.clone_from("git://github.com/facebook/buck.git", "D:\sample")
I am getting error
WindowsError: The system cannot find the file specified
Can someone please tell me if this is how to clone a repo using the library?
You might not have git.ext in your PATH, but that can easily be tested by executing it yourself.
If you see an error, you can either add it to the PATH, or set the GIT_PYTHON_GIT_EXECUTABLEto the executable git-python should execute for git commandline services.

Heroku Cedar Python: requirement in github - clone fails with error 128

i wanted to use the pyfire github library https://github.com/mariano/pyfire
this is what pip freeze produced for me:
-e git+ssh://git#github.com/mariano/pyfire.git#db856bb666c4b381c08f2f4bf7c9ac7aaa233221#egg=pyfire-dev
but when doing so the clone that is being done to install the dependencies fails with error code, i can't
heroku run console
to check out the full error log...
any experience with this or ideas?
thanks a lot in advance
pip freeze appears to produce the wrong results you should be able to modify your requirements.txt to:
git+https://github.com/mariano/pyfire.git#db856bb666c4b381c08f2f4bf7c9ac7aaa233221#egg=pyfire-dev
I realized this was already solved for you, but this didn't work for me or #amrox or #tomtaylor.
If you remove the commit part, it works for me. i.e. changing the line in requirements.txt to:
git+https://github.com/mariano/pyfire.git
When I install the git repo including the specific commit locally, git seems to realize the end part is a specific commit, but when I try this on heroku and track the progress, it is pretty clear it is treating the commit part as a tag. Since there is no tag with that name, that's why it fails. They may be using a different version of git.

Categories

Resources