Removed argparse.py - python

I use Ubuntu 18.04. By mistake, I changed argparse.py file in usr/lib/python3.6. I couldn't fix it and I thought to remove it, so I could reinstall. Now I can't reinstall, whenever I try "pip install argparse" I get an error like this:
Defaulting to user installation because normal site-packages is not writeable
ERROR: Exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/pip/_internal/cli/base_command.py", line 186, in _main status = self.run(options, args)
File "/usr/local/lib/python3.6/dist-packages/pip/_internal/commands/install.py", line 279, in run
session = self.get_default_session(options)
File "/usr/local/lib/python3.6/dist-packages/pip/_internal/cli/req_command.py", line 74, in get_default_session
self._session = self.enter_context(self._build_session(options))
File "/usr/local/lib/python3.6/dist-packages/pip/_internal/cli/req_command.py", line 91, in _build_session
index_urls=self._get_index_urls(options),
File "/usr/local/lib/python3.6/dist-packages/pip/_internal/network/session.py", line 241, in __init__
self.headers["User-Agent"] = user_agent()
File "/usr/local/lib/python3.6/dist-packages/pip/_internal/network/session.py", line 129, in user_agent from pip._vendor import distro
File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/distro.py", line 37, in <module>
import argparse ModuleNotFoundError: No module named 'argparse'
Traceback (most recent call last):
File "/usr/local/bin/pip", line 11, in <module> sys.exit(main())
File "/usr/local/lib/python3.6/dist-packages/pip/_internal/cli/main.py", line 75, in main
return command.main(cmd_args)
File "/usr/local/lib/python3.6/dist-packages/pip/_internal/cli/base_command.py", line 105, in main return self._main(args)
File "/usr/local/lib/python3.6/dist-packages/pip/_internal/cli/base_command.py", line 224, in _main self.handle_pip_version_check(options)
File "/usr/local/lib/python3.6/dist-packages/pip/_internal/cli/req_command.py", line 146, in handle_pip_version_check timeout=min(5, options.timeout)
File "/usr/local/lib/python3.6/dist-packages/pip/_internal/cli/req_command.py", line 91, in _build_session index_urls=self._get_index_urls(options),
File "/usr/local/lib/python3.6/dist-packages/pip/_internal/network/session.py", line 241, in __init__self.headers["User-Agent"] = user_agent()
File "/usr/local/lib/python3.6/dist-packages/pip/_internal/network/session.py", line 129, in user_agent
from pip._vendor import distro
File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/distro.py", line 37, in <module>
import argparse
ModuleNotFoundError: No module named 'argparse'
Could you please help me to fix this?

argparse is part of the standard library, not a third-party module. The standard library is not managed via pip (that is both its blessing and its bane).
So you have to fix or reinstall python itself.

argparse is (since Python 3.2) part of the standard library. Just get the file from the official github (I'm assuming cpython, adapt the version as necessary by selecting the correct branch, the link is for python 3.8) and put it back where the one you deleted was

Related

Python exe crashes when running

I'm running a Python executable file on my PC. I created it using cx_freeze. I ran it and I am getting the following errors:
H:\>cmd /K C:\Executables\Minneapolis\build\exe.win-amd64-3.7\MinneapolisDiscovery.exe
Traceback (most recent call last):
File "C:\Python37\lib\cx_Freeze\initscripts\__startup__.py", line 40, in run
module.run()
File "C:\Python37\lib\cx_Freeze\initscripts\Console.py", line 23, in run
exec(code, {'__name__': '__main__'})
File "MinneapolisDiscovery.py", line 1, in <module>
File "C:\Python37\lib\requests\__init__.py", line 43, in <module>
import urllib3
File "C:\Python37\lib\urllib3\__init__.py", line 8, in <module>
from .connectionpool import (
File "C:\Python37\lib\urllib3\connectionpool.py", line 28, in <module>
from .packages.six.moves import queue
File "C:\Python37\lib\urllib3\packages\six.py", line 92, in __get__
result = self._resolve()
File "C:\Python37\lib\urllib3\packages\six.py", line 115, in _resolve
return _import_module(self.mod)
File "C:\Python37\lib\urllib3\packages\six.py", line 82, in _import_module
__import__(name)
ModuleNotFoundError: No module named 'queue'
It looks like something related to urllib3 or requests, but I've never gotten this error before. Any ideas on what I need to do to get this exe file to run?

Ovirt Python SDK error during openuds installation

I get the following error, How to rectify this issue?
from ovirtsdk.xml import params
ImportError: No module named ovirtsdk.xml
This is the complete log file, Why I get this error and How to rectify it?
python manage.py createcachetable
Traceback (most recent call last):
File "manage.py", line 9, in <module>
execute_from_command_line(sys.argv)
File "/home/hari/openuds/testuds-master/Python-2.7.14/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/home/hari/openuds/testuds-master/Python-2.7.14/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 327, in execute
django.setup()
File "/home/hari/openuds/testuds-master/Python-2.7.14/env/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/hari/openuds/testuds-master/Python-2.7.14/env/lib/python2.7/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/home/hari/openuds/testuds-master/server/src/uds/__init__.py", line 72, in ready
from . import services # to make sure that the packages are initialized at this point
File "/home/hari/openuds/testuds-master/server/src/uds/services/__init__.py", line 73, in <module>
__init__()
File "/home/hari/openuds/testuds-master/server/src/uds/services/__init__.py", line 63, in __init__
__import__('uds.services.' + name, globals(), locals(), [])
File "/home/hari/openuds/testuds-master/server/src/uds/services/OVirt/__init__.py", line 31, in <module>
from .OVirtProvider import Provider
File "/home/hari/openuds/testuds-master/server/src/uds/services/OVirt/OVirtProvider.py", line 44, in <module>
from . import client
File "/home/hari/openuds/testuds-master/server/src/uds/services/OVirt/client/__init__.py", line 33, in <module>
from . import oVirtClient3;
File "/home/hari/openuds/testuds-master/server/src/uds/services/OVirt/client/oVirtClient3.py", line 7, in <module>
from ovirtsdk.xml import params
ImportError: No module named ovirtsdk.xml
You are missing the ovirt-engine-sdk-python package. Note that it requires version 3 of that package, so you can install it via pip like this:
$ pip install ovirt-engine-sdk-python==3.6.9.2
Don't run:
$ pip install ovirt-engine-sdk-python
which would install latest(4) version of the SDK, which isn't compatible with above code.

pip3 not installing packages

I enter the following line into terminal:
pip3 install numpy
this gives me:
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 9, in <module>
load_entry_point('pip==9.0.1', 'console_scripts', 'pip3')()
File "/usr/local/lib/python3.5/dist-packages/pip-9.0.1-py3.5.egg/pip/__init__.py", line 233, in main
return command.main(cmd_args)
File "/usr/local/lib/python3.5/dist-packages/pip-9.0.1-py3.5.egg/pip/basecommand.py", line 251, in main
timeout=min(5, options.timeout)) as session:
File "/usr/local/lib/python3.5/dist-packages/pip-9.0.1-py3.5.egg/pip/basecommand.py", line 72, in _build_session
insecure_hosts=options.trusted_hosts,
File "/usr/local/lib/python3.5/dist-packages/pip-9.0.1-py3.5.egg/pip/download.py", line 329, in __init__
self.headers["User-Agent"] = user_agent()
File "/usr/local/lib/python3.5/dist-packages/pip-9.0.1-py3.5.egg/pip/download.py", line 93, in user_agent
from pip._vendor import distro
File "/usr/local/lib/python3.5/dist-packages/pip-9.0.1-py3.5.egg/pip/_vendor/distro.py", line 1050, in <module>
_distro = LinuxDistribution()
File "/usr/local/lib/python3.5/dist-packages/pip-9.0.1-py3.5.egg/pip/_vendor/distro.py", line 594, in __init__
if include_lsb else {}
File "/usr/local/lib/python3.5/dist-packages/pip-9.0.1-py3.5.egg/pip/_vendor/distro.py", line 931, in _get_lsb_release_info
raise subprocess.CalledProcessError(code, cmd, stdout, stderr)
subprocess.CalledProcessError: Command 'lsb_release -a' returned non-zero exit status 1
Im thinking its a path issue but im not really sure.
This is a bug with the distro package vendored by pip. The bug has been solved but the latest version of pip uses and very old version of distro which doesn't have this bug fix applied.
For now, you can simply try to make the executable available in the path.

Error: The 'elasticsearch' backend requires the installation of 'requests'. How do I fix it?

I´m having a issue when I ran "python manage.py rebuild_index" in my app supported by haystack and elasticsearch.
Python 2.7
Django version 1.6.2
Haystack 2.1.0
Elasticsearch 1.0
Please see the error that is appearing:
Traceback (most recent call last):
File "manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/init.py", line 399, in > execute_from_command_line
utility.execute()
File "/usr/lib/python2.7/site-packages/django/core/management/init.py", line 392, in > execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 242, in >run_from_argv
self.execute(*args, **options.dict)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/usr/lib/python2.7/site-packages/haystack/management/commands/rebuild_index.py", line 15, in handle
call_command('clear_index', **options)
File "/usr/lib/python2.7/site-packages/django/core/management/init.py", line 159, in call_command
return klass.execute(*args, **defaults)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/usr/lib/python2.7/site-packages/haystack/management/commands/clear_index.py", line 48, in handle
backend = connections[backend_name].get_backend()
File "/usr/lib/python2.7/site-packages/haystack/utils/loading.py", line 98, in getitem
self._connections[key] = load_backend(self.connections_info[key]['ENGINE'])(using=key)
File "/usr/lib/python2.7/site-packages/haystack/utils/loading.py", line 51, in load_backend
return import_class(full_backend_path)
File "/usr/lib/python2.7/site-packages/haystack/utils/loading.py", line 18, in import_class
module_itself = importlib.import_module(module_path)
File "/usr/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
import(name)
File "/usr/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 21, in
raise MissingDependency("The 'elasticsearch' backend requires the installation of 'requests'.")
haystack.exceptions.MissingDependency: The 'elasticsearch' backend requires the installation of 'requests'.
I've installed all the packages needed to run those apps however is asking about requests, What is it about?
just do
pip install pyelasticsearch
If you just install requests module through pip this error should go away.

Setting python path for WinPython to use f2py

I installed the Winpython distribution on my copy of Windows 7. Launching iPython consoles and other items from the distribution from within the folder it copied to works fine.
I'd like to use the f2py module from numpy to be able to call Fortran subroutines from Python. My understanding is that f2py must be called from the command line, but the system does not seem to find f2py, returning ImportError: no module named site when I call it either with or without flags. This same error is returned when I try to run python itself from the command line.
When I manually navigate to the Winpython directory (e.g. C:\Users\AGK\WinPython-32bit-2.7.5.3\python-2.7.5) and call f2py -c --help-fcompiler to see if f2py is found there, I receive the following error
Traceback (most recent call last):
File ".\lib\site.py", line 538, in main
main()
File ".\lib\site.py", line 530, in main
known_paths = addusersitepackages(known_paths)
File ".\lib\site.py", line 266, in addusersitepackages
user_site = getusersitepackages()
File ".\lib\site.py", line 241, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File ".\lib\site.py", line 231, in getuserbase
USER_BASE = get_config_var('userbase')
File "C:\Users\AGK\WinPython-32bit-2.7.5.3\python-2.7.5\lib\sysconfig.py",
line 516, in get_config_var
return get_config_vars().get(name)
File "C:\Users\AGK\WinPython-32bit-2.7.5.3\python-2.7.5\lib\sysconfig.py",
line 449, in get_config_vars
import re
File "C:\Users\AGK\WinPython-32bit-2.7.5.3\python-2.7.5\lib\re.py", line 1
05, in <module>
import sre_compile
File "C:\Users\AGK\WinPython-32bit-2.7.5.3\python-2.7.5\lib\sre_parse.py"
", line 14, in <module>
import sre_parse
File "C:\Users\AGK\WinPython-32bit-2.7.5.3\python-2.7.5\lib\sre_constants.py",
line 17, in <module>
from sre_constants import *
File "C:\Users\konings\WinPython-32bit-2.7.5.3\pyt
py", line 18, in <module>
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
Could somebody explain to me what this error means and/or how to use f2py with Winpython? Thanks!
You can set your environment variable PYTHONPATH pointing to the folder where these modules are. This should solve the ImportErrors.

Categories