Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

module 'gitlab' has no attribute 'Gitlab'

Tags:

python

gitlab

I am trying to read the file from gitlab. I created access token in gitlab for this. Downloaded module python-gitlab

I installed module python-gitlab from PyCharm: File --> Settings--> Python interpreter --> python-gitlab

import gitlab
import json
from pprint import pprint
import requests
import urllib.request
# private token authentication
gl = gitlab.Gitlab('https://gitlab.com/..../CSV_HOMEWORK.csv', private_token='xxx')

gl.auth()

# list all projects
projects = gl.projects.list()
for project in projects:
    # print(project) # prints all the meta data for the project
    print("Project: ", project.name)
    print("Gitlab URL: ", project.http_url_to_repo)
    # print("Branches: ", project.repo_branches)
    pprint(project.repository_tree(all=True))
    f = urllib.request.urlopen(project.http_url_to_repo)
    myfile = f.read()
    print(myfile)
    print("\n\n")

after print(gitlab) I have enter image description here

P.S. My file name from where I run my code isn't gitlab.py

like image 737
Aliaksandra Avatar asked Jul 19 '26 17:07

Aliaksandra


2 Answers

You installed the package gitlab instead of python-gitlab.

Even if you installed python-gitlab already, the gitlab package will still conflict, so it must be uninstalled

pip uninstall gitlab
pip install python-gitlab

This is evidenced by the path identified in the error, pointing to a different package in site-packages. If you inspect the files in this path, you'll find it's not those expected to be contained in the python-gitlab package.


Similar problems (not necessarily in this case) may be caused in a circumstance where you've named a module gitlab.py or named a package directory within your project gitlab/.

like image 93
sytech Avatar answered Jul 21 '26 07:07

sytech


The issue can also happen when the file is gitlab.py. Renaming the file will solve the issue, when the package is not conflicting with gitlab.

like image 40
fmdaboville Avatar answered Jul 21 '26 05:07

fmdaboville