remote: ImportError: No module named gitlab

Question:

I wrote gitlab hook with python. And added to post-receive hooks in gitlab server. When i push to remote origin server from my laptop, i get following error. But it works when i run script manually in gitlab server. How can i solve problem?

 Counting objects: 3, done.
 Writing objects: 100% (3/3), 240 bytes | 0 bytes/s, done.
 Total 3 (delta 0), reused 0 (delta 0)
 remote: Traceback (most recent call last):
 remote:   File "push.py", line 4, in <module>
 remote:     import gitlab
 remote: ImportError: No module named gitlab
Asked By: Gokhan MANKARA

||

Answers:

gitlab’s using own python2.7 binary in /opt/gitlab/embedded/bin/ path.
i renamed /opt/gitlab/embedded/bin/python2.7 binary and create symbolic link with /usr/bin/python2.7

After that you must change owner of the python file with git user.

Above solution cause same problem if gitlab use own python binary. Because of that you can run script like this in post-receive hook

/usr/bin/python2.7 some_script.py

Answered By: Gokhan MANKARA

I’ve resolved this problem by using the following command:

/usr/local/bin/python3 -m pip install -U python-gitlab

Answered By: llincolnatal
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.