Unable to run py2 virtual environment in command line - python

I'm trying to run a script (from udacity lesson quiz) which was written in python 2. The course instruction recommends using python 2.6 or 2.7 so I created a virtual environment in anaconda prompt using conda create --name py2 python=2.7 and then installed the required libraries using pip. After activating the py2 environment (version 2.7.18) I tried running a script from the lesson in both atom editor and anaconda prompt and i got SyntaxError in both cases. The error messages look like this:
for Anaconda prompt i got this:
(py2) C:\Users\fayolpc\Desktop\ml-mini-project\ud120-projects>python tools/startup.py
checking for nltk
Traceback (most recent call last):
File "tools/startup.py", line 6, in <module>
import nltk
File "C:\PYTHON\envs\py2\lib\site-packages\nltk\__init__.py", line 128, in <module>
from nltk.collocations import *
File "C:\PYTHON\envs\py2\lib\site-packages\nltk\collocations.py", line 35, in <module>
from nltk.probability import FreqDist
File "C:\PYTHON\envs\py2\lib\site-packages\nltk\probability.py", line 333
print("%*s" % (width, samples[i]), end=" ")
^
SyntaxError: invalid syntax
for atom editor i got this:
File "C:\Users\fayolpc\Desktop\ml-mini-project\ud120-projects\tools\startup.py", line 4
print "checking for nltk"
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("checking for nltk")?
I can't figure out what the problem is and I have done a lot of searching for solution but can't find any. I'd really appreciate if anyone can help me out. By the way I'm new to both programming and this community. Thanks for considering to help.

Related

When I run python3.6 in terminal, it give me "SyntaxError: invalid syntax"

When I try to run python 3.6 it give me this SyntaxError.
$ python3.6
Failed to import the site module
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 73, in <module>
import os
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/os.py", line 678, in <module>
from _collections_abc import MutableMapping
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_collections_abc.py", line 203
return await
^
SyntaxError: invalid syntax
It appears somehow your copy of the standard library file which defines the collections.abc module is corrupted. Looking through the last several versions of the file _collections_abc.py in the Github repository didn't show any versions where line 203 was return await (I didn't look through all of them, so I may be wrong).
The actual syntax error is that the file includes the line return await. In Python 3.6, this is invalid syntax because await is now a keyword which must be followed by an awaitable expression. In previous versions of Python, await was not a keyword, so return await was a valid statement.
Are you sure you installed 3.6 with the command pip install python3.6? and not something like brew install python3.6? There is currently no package for 2.7 or 3.6 called python3.6.
I would suggest deleting this installation and installing 3.6 either through the official downloads or through Homebrew since it looks like you are on a Mac.

An Error when Importing "mp3play" plugin

I downloaded mp3play from pip.But,when I try to import it,it gives me that error:
Traceback (most recent call last):
File "C:/Users/semih/Desktop/hata.py", line 1, in <module>
import mp3play
File "C:\Users\semih\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\mp3play\__init__.py", line 4, in <module>
from .windows import AudioClip as _PlatformSpecificAudioClip
File "C:\Users\semih\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\mp3play\windows.py", line 27
print 'Error %s for "%s": %s' % (str(err), txt, buf)
^
SyntaxError: invalid syntax
Can someone help me please?Thanks!
Your library is for Python 2, but you're trying to use it in Python 3.
Search another library that can do the same thing, search if there's a Python 3 version or use it in Python 2.
As others have mentioned, the version on PyPi was not meant for use in python3 (it was published in 2008). However, if you follow the link to the sourcecode, you end up at this git repo. There was a commit 4 years ago that fixed python3 support, but that version was never uploaded to pypi.
What you can do is:
Download/clone the git
run python setup.py to install the package
enjoy!

Python Portable Install gives error

i am starting to use Databases and am using MariaDB, Got that ready, but i want Python integration so i can get started on the program.
I have downloaded PyMySQL-0.7.10.tar.gz from the official python website
and have unzipped and have navigated an Command Prompt to there using cd (dir).
My command is:
"G:\Python\Portable\Portable Python 3.2.5.1\App\python.exe" setup.py install
(Yes, i am on Windows 10 and i am using Portable Python. This is because i learn it at school but also want to be able to work at it at home.)
The error it returns is the following:
Traceback (most recent call last):
File "setup.py", line 4, in <module>
version_tuple = __import__('pymysql').VERSION
File "C:\Users\Natan Samuel Geldorp.Remytop-PC\Downloads\PyMySQL-0.7.10\pymysql\__init__.py", line 28, in <module>
from .converters import escape_dict, escape_sequence, escape_string
File "C:\Users\Natan Samuel Geldorp.Remytop-PC\Downloads\PyMySQL-0.7.10\pymysql\converters.py", line 60
_escape_table[0] = u'\\0'
^
SyntaxError: invalid syntax
Does anyone know how to fix this?
-Natan
As requested, as an answer:
You need a newer Python version, in 3.0 to 3.2 the u prefix was forbidden, it was allowed again in version 3.3.
Since Portable Python is no longer being developed (according to their site) you need to pick an alternative. One suggested on the site is WinPython.
(Also the PyMySQL site states that the minimum required Python versions are either >= 2.6 or >= 3.3)

pygraphviz error: program neato not found in path

I'm running Windows 7, and using python version 2.7.
I've been trying to use pygraphviz, but whenever I use G.layout() on a graph, I get the error message;
Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
G.layout()
File "C:\Python27\lib\site-packages\pygraphviz\agraph.py", line 1305, in layout
data=self._run_prog(prog,' '.join([args,"-T",fmt]))
File "C:\Python27\lib\site-packages\pygraphviz\agraph.py", line 1251, in _run_prog
runprog=r'"%s"'%self._get_prog(prog)
File "C:\Python27\lib\site-packages\pygraphviz\agraph.py", line 1239, in _get_prog
raise ValueError("Program %s not found in path."%prog)
ValueError: Program neato not found in path.
I know, however, that the Graphviz files are installed, and the directory is in my path (I've manually gone and added it).
I've tried the simlink solution given here but all I get when I enter that into the command line (administrator mode) is a message saying it is not recognized as an internal or external command, operable program, or batch file. I'm not experienced enough to know whether there's something I'm failing to do with that though.
Is there something I can do to make this work?
I had the same problem with conda. Apparently there is something wrong with the libraries. This comment in here worked for me:
https://github.com/conda/conda/issues/1851#issuecomment-314924385
In the Anaconda prompt do both:
conda install -c anaconda graphviz
and
conda install -c anaconda python-graphviz
Then import graphviz will work.

parallel installion of Python 2.7 and 3.3 via Homebrew - pip3 fails

I would like to make the jump and get acquainted with Python 3.
I followed the instructions found here with the installation working flawlessly.
I'm also able to use the provided virtualenv to create enviroments for Python 2 and Python 3 (Followed the instuctions here.). Unfortunalty pip3 fails when no virtualenv is activated. I need to use it to install global modules for python3.
This is the error message:
± |master ✓| → pip3
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python2.7/site-packages/distribute-0.6.45-py2.7.egg/pkg_resources.py", line 51
def _bypass_ensure_directory(name, mode=0777):
^
SyntaxError: invalid token
It looks like pip3 is trying to access distribute of python2. Is there any workaround for this?
I was having the same problem as you were and I had
export PYTHONPATH="/usr/local/lib/python2.7/site-packages:$PYTHONPATH"
in my ~/.bash_profile. Removing that line solved the problem for me. If you have that or something like it in your ~/.bashrc or ~/.bash_profile, try removing it.

Categories

Resources