Syntax error without sudo

When I execute my script without sudo:

$ python main.py 
Traceback (most recent call last):
  File "main.py", line 3, in <module>
    import irc
  File "/Users/judgej4/twitchchat/irc.py", line 3, in <module>
    import asyncio
  File "/Users/judgej4/anaconda3/lib/python3.6/site-packages/asyncio/__init__.py", line 21, in <module>
    from .base_events import *
  File "/Users/judgej4/anaconda3/lib/python3.6/site-packages/asyncio/base_events.py", line 18, in <module>
    import concurrent.futures
  File "/Users/judgej4/anaconda3/lib/python3.6/site-packages/concurrent/futures/__init__.py", line 8, in <module>
    from concurrent.futures._base import (FIRST_COMPLETED,
  File "/Users/judgej4/anaconda3/lib/python3.6/site-packages/concurrent/futures/_base.py", line 381
    raise exception_type, self._exception, self._traceback
                        ^
SyntaxError: invalid syntax

When I execute with sudo, the syntax error disappears and the script runs correctly.

How can I debug this?

EDIT Note: I am using the same python version for each:

$ which python
/Users/judgej4/anaconda3/bin/python
$ sudo which python
/Users/judgej4/anaconda3/bin/python

I noticed that PYTHONPATH contains several directories for the regular user sudo does not do:

/Users/judgej4/anaconda3/lib/python3.6/site-packages
/usr/local/Cellar/apache-spark/2.2.1/libexec/python

and it looks like the error comes from the first directory.

I could remove this directory from my PYTHONPATH, but I would better fix a problem that seems to be with anaconda

EDIT 2

$ python --version
Python 3.6.3 :: Anaconda custom (64-bit)
$ sudo python --version
Python 3.6.3 :: Anaconda custom (64-bit)

EDIT 3

$ command -v python
/Users/judgej4/anaconda3/bin/python
$ sudo command -v python
/Users/judgej4/anaconda3/bin/python
+4
source share
3 answers

The problem is not your python interpreter, but the python library settings. Look at the line that throws the exception:

File "/Users/judgej4/anaconda3/lib/python3.6/site-packages/concurrent/futures/_base.py", line 381
    raise exception_type, self._exception, self._traceback

python 2, python3.6/site-packages/.... , futures python3, python2, , . , root PYTHONPATH

/Users/judgej4/anaconda3/lib/python3.6/site-packages

script sudo: concurrent, /Users/judgej4/anaconda3/lib/python3.6/, futures, /Users/judgej4/anaconda3/lib/python3.6/site-packages.

/Users/judgej4/anaconda3/lib/python3.6/site-packages/concurrent/, .

+3

Python 2 Python 3.6.

, :

  • root python - python2
  • python python3.6

, python2, :

  • sudo python2 main.py
  • python2 main.py
+2

sudo will execute your script with a different version of python - the below commands will confirm this:

sudo type python

type python

I expect the outputs to be different, with the first command printing the path to install python 2

0
source

Source: https://habr.com/ru/post/1693107/


All Articles