invalid syntax when run pylint - python

the following is the stack trace, please suggest
my python version is 2.7
-----------------
pylint
Traceback (most recent call last):
File "E:\Python27\Scripts\pylint-script.py", line 11, in <module>
load_entry_point('pylint==2.0.0', 'console_scripts', 'pylint')()
File "E:\Python27\lib\site-packages\pylint-2.0.0-py2.7.egg\pylint\__init__.py"
, line 17, in run_pylint
from pylint.lint import Run
File "E:\Python27\lib\site-packages\pylint-2.0.0-py2.7.egg\pylint\lint.py", li
ne 75, in <module>
import astroid
File "E:\Python27\lib\site-packages\astroid-2.0.1-py2.7.egg\astroid\__init__.p
y", line 59, in <module>
from astroid.exceptions import *
File "E:\Python27\lib\site-packages\astroid-2.0.1-py2.7.egg\astroid\exceptions
.py", line 13, in <module>
from astroid import util
File "E:\Python27\lib\site-packages\astroid-2.0.1-py2.7.egg\astroid\util.py",
line 148
yield from islice(iterator, size)
^
SyntaxError: invalid syntax
my python version is 2.7

pylint 2.0.0 requires at least Python 3.4.1
The last version that supported Python 2.7 was 1.9.2. So, your fix is to downgrade to 1.9.2.
The specific error message you're seeing is because yield from was added to the language in Python 3.3, so code that uses it can't run in 2.7. But there are probably lots of other errors. After all, the only reason developers drop 2.7 support is so they can use new language features.
If you install it with pip install pylint or py -m pip install pylint using Python 2, it should automatically install 1.9.2 instead of 2.0.0—or, failing that, the installation should fail instead of appearing to succeed. (When I test it myself, that's exactly what happens.)
However, installing with an old version of pip, might cause this problem. If so, upgrade your pip and setuptools. (You definitely want at least pip 10 and setuptools 30… but generally you want the latest version available, so just let it do that.)
py -m pip install --upgrade pip setuptools
If that was your problem, you should have seen a warning, like You are using pip version 6.0, however version 18.0 is available. That warning doesn't look hugely important, but it is—especially if you're staying on 2.7 (or, similarly, if you like to follow the bleeding edge and install beta versions of Python).
Installing with easy_install can definitely cause this. If that's your problem, just stop using easy_install and start using pip.
If you installed it manually instead of by using pip, then you have to do the version checking manually as well. If you have a good reason for doing that, download 1.9.2 and install that manually instead.
At any rate, however you got thing into this situation, you should be able to fix it by uninstalling pylint and then running:
py -m pip install pylint==1.9.2
1. According to its own documentation, it specifically supports 3.4, 3.5, and 3.6. It may also support 3.7 despite saying it doesn't—later versions definitely do, and of course future versions will support even newer versions of Python. But definitely not 2.7.

Related

How do I update python on my Raspberry Pi to at least 3.6?

As some brief background information: I was origianlly trying to use Miniconda (with conda) to install dependencies that I need for my project on my Raspberry Pi. After trying to use Conda to install the SimpleAudio package, I got an error saying that it did not exist, therefore I proceeded to install this through Pip. Pip found the correct package although I get the following error message:
pi#raspberrypi:~ $ pip install simpleaudio
Traceback (most recent call last):
File "/home/pi/miniconda3/bin/pip", line 7, in <module>
from pip._internal.cli.main import main
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/cli/main.py", line 10, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
from pip._internal.cli import cmdoptions
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/cli/cmdoptions.py", line 28, in <module>
from pip._internal.models.target_python import TargetPython
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/models/target_python.py", line 4, in <module>
from pip._internal.utils.misc import normalize_version_info
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/utils/misc.py", line 20, in <module>
from pip._vendor import pkg_resources
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_vendor/pkg_resources/__init__.py", line 92, in <module>
raise RuntimeError("Python 3.5 or later is required")
RuntimeError: Python 3.5 or later is required
It seems I need to update Python, although when I print the verion on Spyder IDE, it says I am already using 3.7.
Have I caused some sort of mismatch between what version my IDE is using and what the default process the terminal uses to look up the version? I noticed that it is looking for the Python version under Miniconda. If I can update If so is there a fix for this?
Please as me for more information if required (I am fairly new to stack overflow).
UPDATE:
I have been able to install the updated version of Python to 3.6 using the following instructions:
https://stackoverflow.com/a/56852714/12361146
This generally solves the scope of this question in terms of how I update Python, but I am still confused as to why Spyder IDE uses a more up-to-date version of Python whereas the terminal shows otherwise.
To answer the question of why Spyder reports a more up-to-date version of Python, here's the reason. The default versions of Python that are installed with Raspbian are 2.7 and 3.5, located in the /usr/bin/ directory. When you install Spyder, however (either independently, or more commonly, using conda), it includes its own installation of Python, which it is configured to use in the IDE, and which is located in a different directory. Hence when you compare the versions, first by entering python3 --version on the command line, and then print(sys.executable) from the Spyder IDE, they're different.
Now the issue with using pip alongside conda for updating the Spyder installation of Python is that it has the potential to mess it up quite badly, so avoid that unless you really know what you're doing. From code you posted above, you have avoided that, though, since that will have impacted the default Raspbian installation of Python, not the Spyder one. Upgrading the latter version should be done using Conda, not pip.
Hopefully you're now all up and running.
You can install newer versions of python using the package manager apt or apt-get.
Start by getting up-to-date package definitions.
$ sudo apt-get update
Then you can show details about the python3 package.
$ apt-cache show python3
When I run that now I get "Version: 3.7.3-1".
To install the python3 package and all its dependencies.
$ sudo apt-get install python3
You will still need to type python3 and pip3 when you run the commands because you are not replacing the built-in python 2.7.
Try these commands to see what you get
$ python --version
$ python3 --version
If you want to change the default python to python3 then have a look at this answer How to change the default python version in Raspberry Pi

Sphinx make file may be using wrong docutils file

I am following this tutorial on how to get started with sphinx documentation for python.
On my mac, I run the make command
$ make html
(as instructed around minute 09:25 in the video), however I get the error
Exception occurred:
File "/Users/me/anaconda/lib/python2.7/site-packages/docutils/writers/html4css1/__init__.py", line 21, in <module>
from docutils.writers import _html_base
ImportError: cannot import name _html_base
From the error, it seems the make file is using an older python 2.7 version of docutils that came installed with the Mac. I believe the make file should be using a more recent version of docutils located here
/Users/me/anaconda/pkgs/sphinx-1.6.3-py36hcd1b3e7_0/lib/python3.6/site-packages/sphinx/utils/docutils.py
This file does not import the package _html_base, which seems to be the problem with the python 2.7 version of the docutils file.
How can I "point the make file to use the python 3.6 docutils"? if that question makes sense. Or is there a better way to fix this?
The problem is that you installed sphinx via the command pip install -U sphinx where pip points to Mac's Python2.7
In order to overcome this, you need to pip3 install -U sphinx (if you have a Python3.x available).

On a Mac how do I remove Openpyxl when it has already been installed before using sudo pip install openpyxl?

Previously openpyxl was installed on a mac. I need to remove it or fix it because it seems to be broken and then I want to reinstall it. Every time i try easy_install -m openpyxl it doesn't work or doing a new install doesn't work. I receive a syntax error.
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/pip-8.1.2-py2.5.egg/pip/__init__.py:208: Warning: 'as' will become a reserved keyword in Python 2.6
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/runpy.py", line 88, in run_module
code = loader.get_code(mod_name)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pkgutil.py", line 283, in get_code
self.code = self._get_delegate().get_code()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pkgutil.py", line 275, in get_code
self.code = compile(source, self.filename, 'exec')
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/pip-8.1.2-py2.5.egg/pip/__init__.py", line 208
except PipError as exc:
I am a def newbie when it comes to not only coding but python.
You can try uninstalling it first using pip with the command sudo pip uninstall openpyxl.
Having said that, it looks like the error is because you're using Python 2.5 and "as" became a reserved keyword in Python 2.6. Your best bet is to install a new version of Python and install openpyxl, or find a version of openpyxl and pip that supports Python 2.5.
Reading up on openpyxl, it looks like the last version that supported Python 2.5 is version 1.7.0. See the package's PyPI page. And the version of pip that supports Python 2.5 is 1.3.1.
So first you need to downgrade pip. The version of pip is FUBARed, so you will have to install pip 1.3.1 from source. Download it from the PyPI page, unpack it and go into the folder with the file setup.py. Then run python setup.py build followed by sudo python setup.py install. This should have downgraded pip.
Next install openpyxl version 1.7.0 sudo pip install openpyxl==1.7.0.

Installing urllib3 for a non-standard Python version

The server I'm coding on has a Python 2.4 binary available in /usr/bin/ and a Python 3.0 binary available in $HOME/bin/. I need to install urllib3 for use with Python 3, but easy_install of course uses the python available system-wide. easy_install installed urllib3 just fine for Python 2.4. I tried to run it with Python 3 but it complains about missing modules:
$ ~/bin/python3.0 /usr/bin/easy_install --prefix=/home/web/local urllib3
Traceback (most recent call last):
File "/usr/bin/easy_install", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named pkg_resources
How might I work around this? Note that I did install pip with easy_install but pip is missing too many dependencies, so I'm stuck with easy_install.
The error you're getting because easy_install isn't installed for Python3.
You want to first install easy_install for Python3 by following the instructions here: http://pypi.python.org/pypi/distribute#installation-instructions
$ curl -O http://python-distribute.org/distribute_setup.py
$ python3.0 distribute_setup.py
Then you'll be able to run ~/bin/easy_install, or easy_install-3.0 to install urllib3:
$ easy_install-3.0 urllib3
Now! Note that urllib3 doesn't officially support Python 3.0… 3.2 is the first supported version, and in general Python 3.2 is the version most library authors are targeting these days, so it might be worth considering switching to 3.2 (not to mention that it's much faster, and other happy things).

Error when running tests of scipy and numpy on OS X Snow Leopard

I am new to stackoverflow as well as Python, and I hope to use stackoverflow to learn and improve my Python programming.
However, as soon as I set up Python, SciPy, NumPy on my Mac, I encountered a problem when I tried running a full test of SciPy and NumPy to verify the install:
>>> import scipy
>>> scipy.test()
Running unit tests for scipy
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
scipy.test()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/testing/nosetester.py", line 318, in test
self._show_system_info()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/testing/nosetester.py", line 187, in _show_system_info
nose = import_nose()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/testing/nosetester.py", line 69, in import_nose
raise ImportError(msg)
ImportError: Need nose >= 0.10.0 for tests - see http://somethingaboutorange.com/mrl/projects/nose
As suggested by the error message, I install this 'nose' package via easy_install, and the install seems successful as I get the following from bash:
mlstr:~ mlstr$ nosetests -V
nosetests version 1.1.2
So I tried the SciPy test again, and it failed with the same message. Can someone please let me know if I need to do anything else to install/configure nose so that it can be used by the unit tests of SciPy and NumPy. Thanks in advance.
UPDATE #1: After trying Rahul's suggestion of using pip to reinstall nose, I think I've found where the problem is: whenever I do easy_install or pip from bash, the package is installed into Python 2.6 directories instead of 2.7 ones. And I think this is because by default 2.6 is the one shipped with Snow Leopard. So what should I do to tell easy_install or pip that I want to install a particular package for Python 2.7? Thanks.
UPDATE #2: By following up my update above, I've found the solution here: easy_install with various versions of python installed, mac osx. It is indeed because that I used the wrong version of easy_install thus my nose installation was for Python 2.6 shipped with Mac OS X. Thanks.
I tried replicating the error that you were encountering. I did not have nose, so I was getting the same error.
I installed nose using pip
sudo pip install nose
After that the scipy.test() worked. I did nothing else. Did you install nose using pip? If not, try using pip.
My machine has :
SciPy version 0.10.0.dev
Nose - 1.1.2
If you want to use your locally installed python version you need to make sure, that this is called when you run python from console.
On a linux machine an alias would do that. Once you run the correct python from your console all the easy_install things will be available in the correct python version.

Categories