Unable to install boto in python3 - python

I am trying to install boto from the source code / pypi, but I am unable to install it using python 3.2. Why is it failing?
c:\boto>..\Python32\python.exe setup.py install
Traceback (most recent call last):
File "setup.py", line 35, in <module>
from boto import __version__
File "c:\boto\boto\__init__.py", line 26, in <mod
ule>
from boto.pyami.config import Config, BotoConfigLocations
File "c:\boto\boto\pyami\config.py", line 185
print s.getvalue()
^
SyntaxError: invalid syntax

print s.getvalue()
is Python 2 syntax. From the README:
If you are interested in trying out boto with Python 3.x, check out the neo branch. This is under active development and the goal is a version of boto that works in Python 2.6, 2.7, and 3.x. Not everything is working just yet but many things are and it's worth a look if you are an active Python 3.x user.

I got it working on Python 3 by installing from the develop branch as the PyPI version did not work at the time of writing. E.g. add this to your requirements.txt:
git+https://github.com/boto/boto.git#develop
Once you find a working version, it's good to freeze your dependency to a specific commit, e.g.:
git+https://github.com/boto/boto.git#5a28d1c6a3b11b979bf32ea7fbfd6d5156c01395
(ideally, of course, we wouldn't need to install from a repository in the first place :)
Update 2015 – can be installed directly from PyPI. See David's comment below.

Related

AssertionError inside of ensure_local_distutils when building a PyInstaller exe using setuptools/distutils

I am trying to convert some Python code into an .exe with PyInstaller. My code uses distutils, which has already caused me some head scratching in the past as it seems to duplicate setuptools functionality, and interacts with it strangely. It e.g. requires an unused import of setuptools to work properly which seems very unpythonic to me.
I need to use both packages inside my project. I import both packages in the order import setuptools; import distutils because the other order throws a warning which is already worrying.
My script runs fine but after I turn it into an exe I get a traceback inside of the suspicious _distutils_hack submodule of setuptools. And yes it just prints a file name with no context.
Traceback (most recent call last):
<18 lines omitted>
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "_distutils_hack\override.py", line 71, in <module>
File "_distutils_hack\__init__.py", line 71, in do_override
File "_distutils_hack\__init__.py", line 59, in ensure_local_distutils
AssertionError: C:\Users\<omitted>\AppData\Local\Temp\_MEI294562\distutils\core.pyc
I am using
Python 3.7.7 on win32 (but I reproduced it with 3.8, 3.9, and 3.10)
pyinstaller==4.8 (Jan 2022) for Windows
distutils==3.7.7 (built-in)
setuptools==60.5.0 (Jan 2022)
Apparently, setuptools is listed on PyPI and thus upgradable, but distutils is not listed on PyPI and thus not upgradable (the version is bundled with Python).
A workaround I found was downgrading to
pip install setuptools==59.8.0
I reported this issue to the project and then confirmed the bug was introduced in setuptools==60.0.0. I'll update this question when I find out more, or it gets fixed.
I reported my issue to the setuptools project, but then the PyInstaller project stepped in to include a workaround on their side. Now any release starting from 5.4 should work! đź‘Ť
pip install pyinstaller>=5.4

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).

invalid syntax when run pylint

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.

Error installing Django: syntax error

I made a few experimentations upgrading from python 2.6.5 to python 2.7.11 in order to get Django to work properly. Then I had to uninstall python 2.7.11 and get back to python 2.6.5 (compatibility issues with other projects). Now, when I try to install django 1.2.1 using pip install django==1.2.1 I get this error:
C:\workspace\internal\trunk\ut_pr_01\src>pip install django==1.2.1
Downloading/unpacking django==1.2.1 Running setup.py egg_info for
package django
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "c:\users\maxim\appdata\local\temp\pip-build\django\setup.py", line
32, in <module>
version = __import__('django').get_version()
File "c:\users\maxim\appdata\local\temp\pip-build\django\django\__init__.py",
line 3, in <module>
from django.utils.version import get_version
File "c:\users\maxim\appdata\local\temp\pip-build\django\django\utils\version.py",
line 7, in <module>
from django.utils.lru_cache import lru_cache
File "c:\users\maxim\appdata\local\temp\pip-build\django\django\utils\lru_cache.py",
line 28
fasttypes = {int, str, frozenset, type(None)},
^
SyntaxError: invalid syntax
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "c:\users\maxim\appdata\local\temp\pip-build\django\setup.py",
line 32, in <module>
version = __import__('django').get_version()
File
"c:\users\maxim\appdata\local\temp\pip-build\django\django\__init__.py",
line 3, in <module>
from django.utils.version import get_version
File
"c:\users\maxim\appdata\local\temp\pip-build\django\django\utils\version.py",
line 7, in <module>
from django.utils.lru_cache import lru_cache
File
"c:\users\maxim\appdata\local\temp\pip-build\django\django\utils\lru_cache.py",
line 28
fasttypes = {int, str, frozenset, type(None)},
^
SyntaxError: invalid syntax
---------------------------------------- Command python setup.py egg_info failed with error code 1 in
c:\users\maxim\appdata\local\temp\pip-build\django Storing complete
log in C:\Users\Maxim\pip\pip.log
It seems like the version of python is what causing the problem but previously I installed any django with same pip and same python versions.
My environment currently:
pip 1.2.1,
python 2.6.5,
windows 10 64bit, needed django version: 1.2.1
Anyone with an idea?
You can have multiple version of Python installed on Windows (what you seem to be using) without any problems. You just have to make sure the default version of Python is set correctly for your situation.
Instead of using an extremely outdated version of django, install the latest version of Python - just choose a different path for it from the installer. So instead of C:\Python27 set it to C:\Python-27 or anything else.
If you are installing Python 3, you don't have to change the path since Python 3 installs itself in C:\Program Files (the default location for programs in Windows) and thus will not clash with Python 2 which installs directly onto the C:\ drive.
Once you have an updated version of Python installed, you just have to make sure that you call that version of Python when you need to install django. To do this effectively, use a Python virtual environment.
Lets assume you have installed the latest version of Python 2 in C:\Python-27, here is how you would install the latest version of django against it:
First, you need to install the virtualenv package. Open a command prompt and then type the following (the > is the prompt, don't type that):
> C:\Python-27\Scripts\pip.exe install virtualenv
A few minutes later you should have virtualenv installed, next step is to install django inside a new virtual environment:
> C:\Python-27\Scripts\virtualenv.exe C:\%USER%\Desktop\django-env
Once that is done, you need to activate the environment, and install django:
> C:\%USER%\Desktop\django-env\bin\activate.bat
(django-env) > pip install django
Now you have the latest version of django installed on an updated version of Python.
Managing these environments can be difficult; so I would suggest downloading a Python IDE. PyCharm is what I use and there is a free community version available. It will make it easy to manage all the different versions of Python for you.
Python 2.6 does not have set literals.
# in python 2.6 only this will work
fasttypes = set(int, str, frozenset, type(None))
# in python 2.7+ this will work as well
fasttypes = {int, str, frozenset, type(None)}
The version of Django you are using is not compatible with python 2.6.5
Support for Python 2.6 was dropped in Django 1.7, so I'm not sure why you get this error when you try to install Django 1.2.1. Maybe a more recent version is residing in the temp\pip-build\ directory. Since it's called temp it should be safe to delete that directory.
In any case, Python 2.6 and the corresponding Django versions are insecure and unsupported. I highly recommend using a current version instead. If other projects need old deprecated Python versions, you should use virtual environments to isolate them.
The problem was solved by installing the Django version I need - 1.2.1 not using pip but downloading the files and manually running:
python setup.py install .

Categories