I'm currently teaching myself Python and am working my way through automatetheboringstuff.com. I'm having trouble installing third party modules in Python 2.4 (this is the newest version I have available to me at work). For instance, when I try to install the requests module so I can work with web pages, I get an invalid syntax error. Here's the procedure I'm using:
Open command line and cd to the folder where the setup.py file for the module is
Type into the command line: setup.py install
Then I get the following error:
File "C:\Users\Username\Desktop\PyRequestsModule\setup.py", line 52
with open('requests/_init__py', 'r') as fd:
^
syntaxError: invalid syntax
I get a similar error every time I try to install a module. Is the issue that I'm running Python 2.4 or am I doing something wrong?
Please do not learn Python 2, if you do not have to use this version for legacy reasons. Its support will end 2020 and most libraries are available for Python 3 too. Some even only for Python 3.
If you can't install a newer version, you can try to use a portable one.
Related
I am embedding python code in my cpp application to provide python-code-runner service. Recently I encountered a problem when I really need to downgrade my python version from 3.8.10 to 3.4.4, so that my application can fit on windows xp.
I used to provided some automatically-installed python 3rd-party packages for my customers to use. Now, as the downgrade of python version, I have to downgrade the 3rd-party packages' version to let my app function fine.
The problem is that I have no idea how to determine whether a 3rd-party package is suitable for python3.4. Is there a way I can test it?
I searched for pypi to get a version suitable for python3.4, but it turns out that this does not work well, as some 3rd-party-libs may rely on other packages with a semanticVersion mark >=.
Take astroid==1.3.8 for an example. I googled and found this version satisfies 3.4.4, so I installed it, and found syntax error when I use import astroid in my python script. The error indicates a syntax error in the lib logilab-common.
File "C:\Python34\lib\site-packages\astroid\__init__.py",line 54, in <module>
from astroid.nodes import *
...... // some traceback
......
File "C:\Python34\lib\site-packages\logilab\common\deprecated.py", line 105
self._proxied: Any = proxied
^
SyntaxError: invalid syntax
It turns out that the package astroid requires logilab-common>=0.63.0, and when I use pip install astroid==1.3.8, it installed the latest logilab-common, which is 1.9.7, and it used a type annotation, which caused this syntax error.
I managed to install logilab-common==0.63.0, and it worked fine when I use import astroid.
Does that mean I can use astroid all fine in python 3.4.4? I am not quite sure whether other functions or apis in this package will raise some syntax error or crash unexpectedly. Is there a way I can test it?
In the case, always installing the minium-satisfied-version of dependency-libs definitely works fine, but that's too much work for me. I want to find a way to test the utility of the libs and their dependency-libs.
I'm working on the implementation of an algorithm which was made to run on Windows and that I need to run on Linux now. It's written with Python 3.7 (but I made it run with Python 3.4 on windows and it worked).
Now, I'd like to run the algorithm on Linux as I said, however when I run the .py file that launches the whole algorithm, I got an error that says:
ImportError : cannot find name 'etree' from 'lxml' (/lib/Python-3.7.4/Lib/lxml/__init__.py)
I don't know how to resolve this error: the lxml library does exist to the indicated path and I installed Python 3.7 (because I originally tried to run it with Python 3.8, then tried 3.4 as it worked on Windows, but each time it couldn't find some method from one or another library...)
You will need to install the library as its not part of the standard Python library, you can install it using PIP by running the following command:
$ pip install lxml
I'm getting:
"ImportError: No module named builtins"
that has only started happening after I installed a later version of PsychoPy (an application that uses Python that is used for writing psychology experiments). I was not getting this problem with an older version
I tried doing "sudo pip install future" like someone else recommended for fixing a similar problem. However, when I do this I get an "invalid syntax" error, and don't know of any other way around the problem. I would greatly appreciate any help on this.
Edit
Could it be you enter the command into a Python prompt? You are supposed to enter that command on the command line of your operating system shell. Which means not inside Python.
Original Answer
Like Deesha already mentioned in their comment, you must install the future package into the Python environment you wish to run PsychoPy in, e.g. via pip:
pip install future
or via conda:
conda install future
This is because newer versions of PsychoPy support both Python 2.7 and 3. The future package is used to ensure the code runs on both platforms.
I'm following this tutorial to install pysqlcipher, but get a syntax error.
I'm working on Ubuntu 14.04 LTS. I have created a virtual environment with "virtualenv" to use Python 3.4. Despite the tutorial (of the link above), I cannot success to install sqlcipher! The installation crashes when I run this:
python setup.py build_sqlcipher
The error message is this one:
File "setup.py", line 64
print "CFLAGS", os.environ['CFLAGS']
^
SyntaxError: invalid syntax
The project only works on Python 2; it is not compatible with Python 3.
This specific error shows the project is using the Python 2 print statement, which was removed from the language in version 3. It was replaced by a function to do printing instead.
In all likelihood, fixing this one line is not going to be enough. You'll have to ask the project maintainers if they have any plans in supporting Python 3. I see the project already has a ticket open asking for support, it looks like the project is already working on supporting this, but it is not ready at this point in time.
Instead, install Python 2.7 on your Ubuntu machine and run the code with that version.
I have just switched from using windows to ubuntu (12.04) and only started learning how to code a couple of months ago, so I'm really a beginner. I tried to do this in windows and I some questions here (didn't get any answers, but my questions were pretty vague) and I'd really appreciate if someone could help.
I am having trouble importing successfully installed packages. My original problem was very similar to the problem here and here. My version of pip would only install the 2.7 versions of modules I needed, even though it is necessary for me to use python 3.2 for some things. I followed the directions provided by AKAidiot for people with ubuntu 12.04 or less. I used the following code
sudo apt-get install python3-setuptools
sudo easy_install3 pip
This seemed to work properly. The only potential problem that I see is that everyone says I should be using the command pip-3.2. That does not work, and I use pip3.2 instead. Next, I try to install geopy. It says geopy installed succesfully, but I do get a bunch of errors.
Installing collected packages: geopy
*** Error compiling '/tmp/pip_build_root/geopy/geopy/geocoders/googlev3.py'...
File "/tmp/pip_build_root/geopy/geopy/geocoders/googlev3.py", line 277
u'pytz must be installed in order to locate timezones. '
^
SyntaxError: invalid syntax
*** Error compiling '/tmp/pip_build_root/geopy/geopy/geocoders/placefinder.py'...
File "/tmp/pip_build_root/geopy/geopy/geocoders/placefinder.py", line 72
signature_method=u"HMAC-SHA1",
^
SyntaxError: invalid syntax
*** Error compiling '/tmp/pip_build_root/geopy/geopy/location.py'...
File "/tmp/pip_build_root/geopy/geopy/location.py", line 21
def __init__(self, address=u"", point=None, raw=None):
^
SyntaxError: invalid syntax
Successfully installed geopy
Looking at the first error message, I thought a problem was the lack of pytz. I used `pip3.2 install pytz' and 'import pytz' No error messages showed up, and it seems to work properly. I then uninstalled geopy, and reinstalled geopy. The error message about the missing pytz did not dissappear.
Here is the error message when I try to import geopy.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.2/dist-packages/geopy/__init__.py", line 10, in <module>
from geopy.location import Location
File "/usr/local/lib/python3.2/dist-packages/geopy/location.py", line 21
def __init__(self, address=u"", point=None, raw=None):
I attempted to try this for other modules. These other modules are not vital for my current project, but I thought maybe there was a problem particular to geopy. When I tried to use pip3.2 install psycopg2 (and later pandas), it did not even install correctly. I got the following error message
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_root/psycopg2
Storing debug log for failure in /home/ravi/.pip/pip.log
Other modules, such as Geocoder and sqlalchemy had problems similar to geopy. Only pytz installed correctly.
When I try to import the package I get the following error.
I looked through stack exchange for people who have had similar problems. Here are links to several potential answers I found. I am not sure I fully understood the answers to these problems, but I am pretty sure that these people face a problem different to the one I have. However, just to check I did
import sys
print(sys.path)
and in both the error message when I do import and the sys.path contain /usr/local/lib/python3.2/dist-packages
I'm not sure if it useful to know, but I installed python 3.2 using the Deadsnakes PPA, using the instructions provided here Everything works exactly as it should in python 2.7, and using virtualenv caused the same problems.
Apologies for the length of the question, and the fact that it is very specific, but I'm really desperate.