I'm trying to pull from a remote repo in a local one with this code:
repo = git.Repo('/home/user/repo/')
o = repo.remotes.origin
try:
o.pull()
except:
logging.exception("oops:")
This fails miserably with the following traceback:
Traceback (most recent call last):
File "/home/user/my_site/app/app.py", line 58, in regen_logs
o.pull()
File "/home/user/my_site/venv/lib/python2.7/site-packages/git/remote.py", line 665, in pull
proc = self.repo.git.pull(self, refspec, with_extended_output=True, as_process=True, v=True, **kwargs)
File "/home/user/my_site/venv/lib/python2.7/site-packages/git/cmd.py", line 440, in <lambda>
return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
File "/home/user/my_site/venv/lib/python2.7/site-packages/git/cmd.py", line 834, in _call_process
return self.execute(make_call(), **_kwargs)
File "/home/user/my_site/venv/lib/python2.7/site-packages/git/cmd.py", line 576, in execute
raise GitCommandNotFound(str(err))
GitCommandNotFound: [Errno 2] No such file or directory
However, when doing the exact three commands (Repo, set origin, pull()) in an interactive session, it works just fine:
>>> import git
>>> repo = git.Repo('/home/user/repo')
>>> o = repo.remotes.origin
>>> o.pull()
[<git.remote.FetchInfo object at 0x242d2b8>]
I do have Git installed on the system:
$ rpm -q git
git-1.8.3.1-6.el7.x86_64
Any clues what I'm doing wrong here?
Found the culprit. Turns out gunicorn, which I used to start the app, clears out most environment variables, and defines a PATH pointing to the virtual environment's directory. Thus, the git executable could not be located anywhere. I fixed this by calling gunicorn with an extra option:
-e GIT_PYTHON_GIT_EXECUTABLE=/usr/bin/git
You need to set path to git before import git, like this:
import os
os.environ['GIT_PYTHON_GIT_EXECUTABLE'] = '/usr/local/bin/git'
from git import Repo
Related
At the start, when i installed python, pip was installed automatically but somehow i messed with the administrator access in windows and messed it very bad,
By reading some online articles, I downloaded the get-pip.py and tried to run it with python in that same folder: python get-pip.py
But the error i get is :
Traceback (most recent call last):
File "get-pip.py", line 23484, in <module>
main()
File "get-pip.py", line 187, in main
tmpdir = tempfile.mkdtemp()
File "C:\Users\Vamsi\AppData\Local\Programs\Python\Python38-32\lib\tempfile.py", line 348, in mkdtemp
prefix, suffix, dir, output_type = _sanitize_params(prefix, suffix, dir)
File "C:\Users\Vamsi\AppData\Local\Programs\Python\Python38-32\lib\tempfile.py", line 117, in _sanitize_params
dir = gettempdir()
File "C:\Users\Vamsi\AppData\Local\Programs\Python\Python38-32\lib\tempfile.py", line 286, in gettempdir
tempdir = _get_default_tempdir()
File "C:\Users\Vamsi\AppData\Local\Programs\Python\Python38-32\lib\tempfile.py", line 218, in _get_default_tempdir
raise FileNotFoundError(_errno.ENOENT,
FileNotFoundError: [Errno 2] No usable temporary directory found in ['C:\\Users\\Vamsi\\AppData\\Local\\Temp', 'C:\\Users\\Vamsi\\AppData\\Local\\Temp', 'C:\\Users\\Vamsi\\AppData\\Local\\Temp', 'C:\\WINDOWS\\Temp', 'c:\\temp', 'c:\\tmp', '\\temp', '\\tmp', 'C:\\Users\\Vamsi']
In order to run get-pip.py you need make sure that you are in the directory where it is installed in. For instance i see that the dirctory you are in is C:\Users\Vamsi make sure that it is saved to this directory or cd to the right one.
trying to init project tree using repo tool but having a failure on assigning local identity:
repo init -u git#github.com:XXX.git -b repo-rocko --config-name
returns:
`
Traceback (most recent call last):
File "/home/user/projects/repo.test/.repo/repo/main.py", line 531, in <module>
_Main(sys.argv[1:])
File "/home/user/projects/repo.test/.repo/repo/main.py", line 507, in _Main
result = repo._Run(argv) or 0
File "/home/user/projects/repo.test/.repo/repo/main.py", line 180, in _Run
result = cmd.Execute(copts, cargs)
File "/home/user/projects/repo.test/.repo/repo/subcmds/init.py", line 404, in Execute
self._ConfigureUser()
File "/home/user/projects/repo.test/.repo/repo/subcmds/init.py", line 298, in _ConfigureUser
name = self._Prompt('Your Name', mp.UserName)
File "/home/user/projects/repo.test/.repo/repo/project.py", line 784, in UserName
self._LoadUserIdentity()
File "/home/user/projects/repo.test/.repo/repo/project.py", line 797, in _LoadUserIdentity
u = self.bare_git.var('GIT_COMMITTER_IDENT')
File "/home/user/projects/repo.test/.repo/repo/project.py", line 2747, in runner
(self._project.name, name, p.stderr))
error.GitError: manifests var:
*** Please tell me who you are.
Run
git config --global user.email "you#example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
`
but when trying to use git to config identity:
git config user.name "Test test"
having a failure:
fatal: not in a git directory
and GLOBAL setting is NOT an option for this case because according to the documentation will store identity in ~/.gitconfig file rather than the repository .git/config and will compromise other repo runs on other projects in other folders.
the google repo script option --config-name is broken (not working as supposed to be) as for the moment on version:
`
repo version v1.12.37
(from https://gerrit.googlesource.com/git-repo)
repo launcher version 1.23
(from /usr/bin/repo)
git version 2.14.1
Python 2.7.14 (default, Sep 23 2017, 22:06:14)
[GCC 7.2.0]
`
but there is a work-around:
immediately after repo init command but before following repo sync command to modify already existing file (repo will generate this file automatically):
.repo/manifests.git/config
by adding identity as following lines to the bottom of the file:
`
[user]
email = user#yourdomain.com
name = User Name
`
I am trying to use the grammar-check 1.3.1 library for Python
I have installed it using the pip commands
$ pip install --upgrade 3to2
$ pip install --upgrade language-check
I also unzipped the LanguageTool file from this link and moved it to C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check
Then I tried to run a test program
import grammar_check
tool = grammar_check.LanguageTool('en-GB')
text = 'This are bad.'
matches = tool.check(text)
len(matches)
But I got this error:
Traceback (most recent call last):
File "grammar-checker-test.py", line 2, in <module>
tool = grammar_check.LanguageTool('en-GB')
File "C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check\__init__.py", line 196, in __init__
self._language = LanguageTag(language)
File "C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check\__init__.py", line 405, in __new__
return unicode.__new__(cls, cls._normalize(tag))
File "C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check\__init__.py", line 426, in _normalize
for language in get_languages())
File "C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check\__init__.py", line 485, in get_languages
languages = LanguageTool._get_languages()
File "C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check\__init__.py", line 286, in _get_languages
for e in cls._get_root(url, num_tries=1):
File "C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check\__init__.py", line 311, in _get_root
raise Error(u'{}: {}'.format(cls._url, e))
grammar_check.Error: http://127.0.0.1:8081: HTTP Error 400: Bad Request
How can I solve this error?
I had this error:
grammar_check.Error: http://127.0.0.1:8081:
I am not sure why you have to start server on your local machine as this piece of code does exactly that:
tool = grammar_check.LanguageTool('en-GB')
If you will have one more language_tool server running on 8081, then it will try to start server on port 8082 and if even that is busy on 8083 and then will fail (which was happening in my case).
Anyways for my error, I had to debug a lot and finally figured out that server was not able to run as my JAVA runtime environment was messed up.
The problem was that I wasn't running the LanguageTool server.
In order to do that I have to check if I have the LanguageTool folder (its version must be < 3.3, in my case it's the 2.2) inside my grammar_check folder.
Then using the cmd shell I have to move into this LanguageTool folder, which in my case is located in this path:
C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check\LanguageTool-2.2
than, I have to run the server with this command
java -cp languagetool-server.jar org.languagetool.server.HTTPServer --port 8081
and voilĂ grammar_check is working well
I'm using ubuntu 15.04, every time I pull one of my repos from bitbucket to another location on my computer I can't run the program because I get a Import Error. I then try using pip freeze then I get this error
Exception:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 22, in main
status = self.run(options, args)
File "/usr/lib/python3/dist-packages/pip/commands/freeze.py, line 74, in run
req = pip.FrozenRequirement.from_dist(dist, dependency_links, find_tags=find_tags)
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 299, in from_dist
assert len(specs) == 1 and specs[0][0] == '=='
AssertionError
Storing debug log for failure in /home/josh//.pip/pip.log
The virtualenv that got pulled with the repo is activated when I try to run the program/pip freeze
The path of the project root is hardcoded when the virtual environment is initiated. Recreate your virtual environment if the project root is different.
I'm trying to run python setup.py a small script on a Linode instance where I'm running Flask + sqlalchemy (mysql).
#filename - setup.py
from daaru import db
def init_db():
db.drop_all()
db.create_all()
init_db()
This is the error I'm getting -
Traceback (most recent call last):
File "setup.py", line 21, in <module>
init_db()
File "setup.py", line 9, in init_db
db.drop_all()
File "/home/captain/public/daaru/v1/local/lib/python2.7/site-packages/flask_sqlalchemy.py", line 830, in drop_all
self._execute_for_all_tables(app, bind, 'drop_all')
File "/home/captain/public/daaru/v1/local/lib/python2.7/site-packages/flask_sqlalchemy.py", line 814, in _execute_for_all_tables
op(bind=self.get_engine(app, bind), tables=tables)
File "/home/captain/public/daaru/v1/local/lib/python2.7/site-packages/flask_sqlalchemy.py", line 763, in get_engine
return connector.get_engine()
File "/home/captain/public/daaru/v1/local/lib/python2.7/site-packages/flask_sqlalchemy.py", line 443, in get_engine
self._engine = rv = sqlalchemy.create_engine(info, **options)
File "/home/captain/public/daaru/v1/local/lib/python2.7/site-packages/sqlalchemy/engine/__init__.py", line 338, in create_engine
return strategy.create(*args, **kwargs)
File "/home/captain/public/daaru/v1/local/lib/python2.7/site-packages/sqlalchemy/engine/strategies.py", line 64, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/home/captain/public/daaru/v1/local/lib/python2.7/site-packages/sqlalchemy/connectors/mysqldb.py", line 52, in dbapi
return __import__('MySQLdb')
ImportError: No module named MySQLdb
The funny part is that when I log into the server, activate the virtual env (named v1), and run init_db in ipython everything works as expected. But when I run it as a script, it gives me an ImportError for the module named MySQLdb. MySQLdb has a systemwide installation using apt-get install python-mysqldb as this package is not available via pip.
What am I doing wrong here?
Running pip freeze on the server shows me this:
Flask==0.9
Flask-SQLAlchemy==0.16
Jinja2==2.6
SQLAlchemy==0.7.9
Werkzeug==0.8.3
argparse==1.2.1
wsgiref==0.1.2
Is the error coming because mysqldb package is not found in the venv? Why isn't then the systemwide installation of that package being used?
I used this blog post to install mysql-python in my venv. Everything works likes a charm now. Thanks.
I've also added a fabfile to automate deployment -
from fabric.api import *
env.user = "host"
env.hosts = ["hostname"]
env.directory = "/home/captain/public/daaru"
env.activate = "source /home/captain/public/daaru/v1/bin/activate"
def deploy():
with cd(env.directory):
run("git pull")
run("sudo service apache2 reload")
def virtualenv(command):
with cd(env.directory), prefix(env.activate):
run(command)
def populate_db():
virtualenv("python setup.py")
def freeze():
""" command for testing virtualenv """
virtualenv("pip freeze")
I just ran into this, and the simple, dirty workaround for me was to cp -r /usr/lib/python2.7/dist-packages/*mysql* $VIRTUALENV/lib/python2.7/dist-packages/ and cp -r /usr/lib/python2.7/dist-packages/*MySQL* $VIRTUALENV/lib/python2.7/dist-packages/, which picked up all needed parts.
Looking into it more it turned out that pip install MySQL-python failed in the virtualenv due to libmysqlclient-dev not being installed via apt. Hope this helps.