Why does python35 import try to load python27 package? - python

I have python2.7 and python3.5 installed via Macports. I am trying to get neovim up and running and for this I ran
$ sudo pip2 install neovim
$ sudo pip-3.5 install neovim
Which installs the packages into different subdirs of /opt/local/Library/Frameworks/Python.framework/Versions/. Now when running Python 3.5, import neovim tries to load the 2.7 package (which fails), as I can see from the stack trace.
The full error is this:
$ python3.5 -c "import neovim"
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/neovim/msgpack_rpc/event_loop/__init__.py", line 7, in <module>
from .uv import UvEventLoop
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/neovim/msgpack_rpc/event_loop/uv.py", line 5, in <module>
import pyuv
ImportError: No module named 'pyuv'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/neovim/msgpack_rpc/event_loop/asyncio.py", line 19, in <module>
import asyncio
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/__init__.py", line 21, in <module>
from .base_events import *
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/base_events.py", line 18, in <module>
import concurrent.futures
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/concurrent/futures/__init__.py", line 8, in <module>
from concurrent.futures._base import (FIRST_COMPLETED,
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/concurrent/futures/_base.py", line 357
raise type(self._exception), self._exception, self._traceback
^
SyntaxError: invalid syntax
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/neovim/__init__.py", line 11, in <module>
from .msgpack_rpc import (ErrorResponse, child_session, socket_session,
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/neovim/msgpack_rpc/__init__.py", line 8, in <module>
from .event_loop import EventLoop
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/neovim/msgpack_rpc/event_loop/__init__.py", line 12, in <module>
from .asyncio import AsyncioEventLoop
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/neovim/msgpack_rpc/event_loop/asyncio.py", line 22, in <module>
import trollius as asyncio
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/trollius/__init__.py", line 21, in <module>
from .base_events import *
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/trollius/base_events.py", line 39, in <module>
from . import coroutines
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/trollius/coroutines.py", line 16, in <module>
from . import futures
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/trollius/futures.py", line 19, in <module>
from . import executor
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/trollius/executor.py", line 12, in <module>
import concurrent.futures
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/concurrent/futures/__init__.py", line 8, in <module>
from concurrent.futures._base import (FIRST_COMPLETED,
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/concurrent/futures/_base.py", line 357
raise type(self._exception), self._exception, self._traceback
^
SyntaxError: invalid syntax
What do I have to do in order for Python 2.7 and 3 to coexist peacefully on my system?

I recently had this problem as well, but it was not related to PYTHONPATH, which on my machine was unset. In my situation Python and pip were installed via MacPorts. Cleaning, self-updating MacPorts and then updating pip to the most recent version, and then running the following resolved the issue:
port select --set pip pip35

Related

Broken Conda Installation After Conda Update Python

I have tried upgrading Python version on a Miniconda installation by running conda update python. The version was being taken from 3.8 to 3.10. This seems to have broken the installation. No matter what command I run, I get the following:
➜ project conda activate
Traceback (most recent call last):
File "/home/user/miniconda3/lib/python3.10/site-packages/conda/common/serialize.py", line 13, in <module>
import ruamel_yaml as yaml
ModuleNotFoundError: No module named 'ruamel_yaml'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/user/miniconda3/lib/python3.10/site-packages/conda/common/serialize.py", line 16, in <module>
import ruamel.yaml as yaml
ModuleNotFoundError: No module named 'ruamel'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/user/miniconda3/bin/conda", line 15, in <module>
sys.exit(main())
File "/home/user/miniconda3/lib/python3.10/site-packages/conda/cli/main.py", line 118, in main
from ..exceptions import conda_exception_handler
File "/home/user/miniconda3/lib/python3.10/site-packages/conda/exceptions.py", line 24, in <module>
from .models.channel import Channel
File "/home/user/miniconda3/lib/python3.10/site-packages/conda/models/channel.py", line 17, in <module>
from ..base.context import context, Context
File "/home/user/miniconda3/lib/python3.10/site-packages/conda/base/context.py", line 55, in <module>
from ..common.configuration import (Configuration, ConfigurationLoadError, MapParameter,
File "/home/user/miniconda3/lib/python3.10/site-packages/conda/common/configuration.py", line 42, in <module>
from .serialize import yaml_round_trip_load
File "/home/user/miniconda3/lib/python3.10/site-packages/conda/common/serialize.py", line 18, in <module>
raise ImportError("No yaml library available. To proceed, conda install ruamel_yaml")
ImportError: No yaml library available. To proceed, conda install ruamel_yaml
Help on fixing this is appreciated.

Terminal does not start in Ubuntu 18.04

I tried to install Django Framework in Ubuntu. and i am using python 3.8. but in normal instalation, Django 1.1 had been installed. and i changed the python3 alternative to python3.8 . and usuing python3 -m pip install django. and i installed Django(v 3.3) and used it. but after the changing the alternative, the Terminal doesn't open and start.
i deleted python3.6 from my ubuntu. and the problems had been started after that.
it seems some programs in linux run in python3.6 and after deleting that,
i can't fix the problems and the Terminal windows does not open. i tried other ways (changing the gnome-terminal file, changing the alternative to default v3.6 and fix the Broken distro), but they didn't help me. i can't open Terminal, and when i ran sudo apt update i recieved this Errors:
Any idea?
File has unexpected size (1133 != 1128). Mirror sync in progress? [IP: ***.**.***.** 80]
Release file created at: Wed, 06 May 2020 19:27:45 +0000 Fetched 1,762 B in 2s (932 B/s) Traceback (most recent call last): File "/usr/lib/cnf-update-db", line 8, in <module>
from CommandNotFound.db.creator import DbCreator File "/usr/lib/python3/dist-packages/CommandNotFound/db/creator.py", line 7, in <module>
import sqlite3 File "/usr/lib/python3.6/sqlite3/__init__.py", line 23, in <module>
from sqlite3.dbapi2 import * File "/usr/lib/python3.6/sqlite3/dbapi2.py", line 23, in <module>
import datetime File "/usr/lib/python3.6/datetime.py", line 8, in <module>
import math as _math ModuleNotFoundError: No module named 'math' Error in sys.excepthook: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report File "/usr/lib/python3/dist-packages/apport/report.py", line 12, in <module>
import subprocess, tempfile, os.path, re, pwd, grp, os, time, io File "/usr/lib/python3.6/subprocess.py", line 136, in <module>
import _posixsubprocess ModuleNotFoundError: No module named '_posixsubprocess'
Original exception was: Traceback (most recent call last): File "/usr/lib/cnf-update-db", line 8, in <module>
from CommandNotFound.db.creator import DbCreator File "/usr/lib/python3/dist-packages/CommandNotFound/db/creator.py", line 7, in <module>
import sqlite3 File "/usr/lib/python3.6/sqlite3/__init__.py", line 23, in <module>
from sqlite3.dbapi2 import * File "/usr/lib/python3.6/sqlite3/dbapi2.py", line 23, in <module>
import datetime File "/usr/lib/python3.6/datetime.py", line 8, in <module>
import math as _math ModuleNotFoundError: No module named 'math' Reading package lists... Done E: Failed to fetch http://dl.google.com/linux/chrome/deb/dists/stable/main/binary-amd64/Packages.gz File has unexpected size (1133 != 1128). Mirror sync in progress? [IP:
* 80] Hashes of expected file:
- Filesize:1128 [weak]
- SHA256:*
- SHA1:*
- MD5Sum:*
Release file created at: Wed, 06 May 2020 19:27:45 +0000 E: Some index files failed to download. They have been ignored, or old ones used instead. E: Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w /var/lib/command-not-found/ -a -e /usr/lib/cnf-update-db; then /usr/lib/cnf-update-db > /dev/null; fi' E: Sub-process returned an error code
and below result showed when i tried to run django-admin:
Traceback (most recent call last):
File "/usr/bin/django-admin", line 5, in <module>
from django.core.management import execute_from_command_line
File "/home/pytm/.local/lib/python3.6/site-packages/django/__init__.py", line 1, in <module>
from django.utils.version import get_version
File "/home/pytm/.local/lib/python3.6/site-packages/django/utils/version.py", line 1, in <module>
import datetime
File "/usr/lib/python3.6/datetime.py", line 8, in <module>
import math as _math
ModuleNotFoundError: No module named 'math'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 12, in <module>
import subprocess, tempfile, os.path, re, pwd, grp, os, time, io
File "/usr/lib/python3.6/subprocess.py", line 136, in <module>
import _posixsubprocess
ModuleNotFoundError: No module named '_posixsubprocess'
Original exception was:
Traceback (most recent call last):
File "/usr/bin/django-admin", line 5, in <module>
from django.core.management import execute_from_command_line
File "/home/pytm/.local/lib/python3.6/site-packages/django/__init__.py", line 1, in <module>
from django.utils.version import get_version
File "/home/pytm/.local/lib/python3.6/site-packages/django/utils/version.py", line 1, in <module>
import datetime
File "/usr/lib/python3.6/datetime.py", line 8, in <module>
import math as _math
ModuleNotFoundError: No module named 'math'
profiling:/home/user/Downloads/Python-3.6.10/Programs/python.gcda:Cannot open
profiling:/home/user/Downloads/Python-3.6.10/Modules/xxsubtype.gcda:Cannot open
after a few hours, i found a way to fix the problems.
First, I made a backup of all my data(I would recommend to everyone trying this). Although it worked for me, it may fail for some reason on your machine and you don't want to lose your data.
I ran the following commands to remove the old version of python3.6 without removing all the dependencies and to directly install the default version.
sudo dpkg --remove --force-depends python3.6 python3.6-minimal libpython3.6-minimal libpython3.6-stdlib
sudo apt-get install python3.6 python3.6-minimal libpython3.6-minimal libpython3.6-stdlib
I ran sudo apt-get update and sudo apt-get upgrade before rebooting my machine.
everything became ok..

Syntax Error:Invalid syntax when installing django in cent os 6.9

I am getting the following error when executing this command "sudo pip install django"
Traceback (most recent call last):
File "/usr/bin/pip", line 7, in <module>
from pip._internal import main
File "/usr/lib/python2.6/site-packages/pip/_internal/__init__.py", line 42, in <module>
from pip._internal import cmdoptions
File "/usr/lib/python2.6/site-packages/pip/_internal/cmdoptions.py", line 16, in <module>
from pip._internal.index import (
File "/usr/lib/python2.6/site-packages/pip/_internal/index.py", line 526
{str(c.version) for c in all_candidates},
^
SyntaxError: invalid syntax
And python installed version is Python 2.7.11 using this command python -V

Python: pip is installed but not working in windows

I have installed python 3.6.0, you don't need to install pip manually if you are using python (>3.3). But When I am trying to access pip (pip --version), it throws me two errors which mainly relate to not finding the module.
Description is given below.
C:\Users\sharma6>pip --version
Traceback (most recent call last):
File "c:\python360\lib\site-packages\pip\_vendor\requests\packages\__init__.py", line 27, in <module>
from . import urllib3
File "c:\python360\lib\site-packages\pip\_vendor\requests\packages\urllib3\__init__.py", line 8, in <module>
from .connectionpool import (
File "c:\python360\lib\site-packages\pip\_vendor\requests\packages\urllib3\connectionpool.py", line 7, in <module>
from socket import error as SocketError, timeout as SocketTimeout
File "c:\python360\lib\socket.py", line 49, in <module>
import _socket
zipimport.ZipImportError: can't find module '_socket'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\python360\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\python360\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\python360\Scripts\pip.exe\__main__.py", line 5, in <module>
File "c:\python360\lib\site-packages\pip\__init__.py", line 21, in <module>
from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
File "c:\python360\lib\site-packages\pip\_vendor\requests\__init__.py", line 62, in <module>
from .packages.urllib3.exceptions import DependencyWarning
File "c:\python360\lib\site-packages\pip\_vendor\requests\packages\__init__.py", line 29, in <module>
import urllib3
ModuleNotFoundError: No module named 'urllib3'
Even when I import socket (>>>import socket)in python interpreter , It shows me "Can not found the module" error .
>>> import socket
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\python352\lib\socket.py", line 49, in <module>
import _socket
zipimport.ZipImportError: can't find module '_socket
Could someone tell me about the errors and how to resolve them because I need pip to work properly.
Add your all path in your system variable instead of adding in user variable.
It worked for me!!! :)
You should try to write
python -m pip --version
If this gives an error message, install pip by downloading get-pip.py from https://pip.pypa.io/en/stable/installing/ and install with
python get-pip.py
Installing with pip is then done by
python -m pip install [package name]

How to install requests module for Python 3.1 ubuntu server 10.04?

I have a ubuntu server.(10.04)
I don't install requests module. I try pip and other methods. Usually ;
$ sudo pip install requests
Traceback (most recent call last):
File "/usr/local/lib/python3.1/dist-packages/pip-1.5.5-py3.1.egg/pip/_vendor/requests/packages/urllib3/packages/ssl_match_hostname/__init__.py", line 3, in <module>
from ssl import CertificateError, match_hostname
ImportError: cannot import name CertificateError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.1/dist-packages/pip-1.5.5-py3.1.egg/pip/_vendor/requests/packages/urllib3/packages/ssl_match_hostname/__init__.py", line 7, in <module>
from backports.ssl_match_hostname import CertificateError, match_hostname
ImportError: No module named backports.ssl_match_hostname
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 9, in <module>
load_entry_point('pip==1.5.5', 'console_scripts', 'pip')()
File "/usr/local/lib/python3.1/dist-packages/distribute-0.6.49-py3.1.egg/pkg_resources.py", line 345, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/local/lib/python3.1/dist-packages/distribute-0.6.49-py3.1.egg/pkg_resources.py", line 2382, in load_entry_point
return ep.load()
File "/usr/local/lib/python3.1/dist-packages/distribute-0.6.49-py3.1.egg/pkg_resources.py", line 2088, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/usr/local/lib/python3.1/dist-packages/pip-1.5.5-py3.1.egg/pip/__init__.py", line 11, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/usr/local/lib/python3.1/dist-packages/pip-1.5.5-py3.1.egg/pip/vcs/mercurial.py", line 9, in <module>
from pip.download import path_to_url
File "/usr/local/lib/python3.1/dist-packages/pip-1.5.5-py3.1.egg/pip/download.py", line 22, in <module>
from pip._vendor import requests, six
File "/usr/local/lib/python3.1/dist-packages/pip-1.5.5-py3.1.egg/pip/_vendor/requests/__init__.py", line 58, in <module>
from . import utils
File "/usr/local/lib/python3.1/dist-packages/pip-1.5.5-py3.1.egg/pip/_vendor/requests/utils.py", line 25, in <module>
from .compat import parse_http_list as _parse_list_header
File "/usr/local/lib/python3.1/dist-packages/pip-1.5.5-py3.1.egg/pip/_vendor/requests/compat.py", line 7, in <module>
from .packages import chardet
File "/usr/local/lib/python3.1/dist-packages/pip-1.5.5-py3.1.egg/pip/_vendor/requests/packages/__init__.py", line 3, in <module>
from . import urllib3
File "/usr/local/lib/python3.1/dist-packages/pip-1.5.5-py3.1.egg/pip/_vendor/requests/packages/urllib3/__init__.py", line 16, in <module>
from .connectionpool import (
File "/usr/local/lib/python3.1/dist-packages/pip-1.5.5-py3.1.egg/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 31, in <module>
from .packages.ssl_match_hostname import CertificateError
File "/usr/local/lib/python3.1/dist-packages/pip-1.5.5-py3.1.egg/pip/_vendor/requests/packages/urllib3/packages/__init__.py", line 3, in <module>
from . import ssl_match_hostname
File "/usr/local/lib/python3.1/dist-packages/pip-1.5.5-py3.1.egg/pip/_vendor/requests/packages/urllib3/packages/ssl_match_hostname/__init__.py", line 10, in <module>
from _implementation import CertificateError, match_hostname
ImportError: No module named _implementation
I guess I have already setup pip 3.1. But following
$ pip -V
Then I see same problem. How to install requests module for Python 3.1 ubuntu server 10.04?
Have you tried easy_install requests?
Or you could try a non-fancy way. Google requests package, download it, unzip it and then run setup.py script like this:
python setup.py install
Have you tried pip install backports.ssl-match-hostname
Probably no harm to upgrade Python either.

Categories