Syntax error resulting from builtin functions in Python33.exe - python-3.x

I'm quite new to python and I just installed python 3.3.2 in my Win 8 64bit PC.
I tried typing in several builtin functions and I get a syntax error for all of them
For example:-
>>>print len("parrot")
File "<stdin>", line 1
print len("parrot")
^
SyntaxError: invalid syntax
I uninstalled/reinstalled python several times and added the path variable automatically during installation as well as manually after installation.
I suspect this might be something related to Win 8 but I'm not sure. Does anyone else have this issue with Python33 on Win8?
Solutions to get python going would be greatly appreciated.
Thanks!

print is now a function
print(len("parrot"))
should work

Related

switched to mac and while running python programs in my vs code get SyntaxError: invalid syntax >>> /usr/local/bin/python3

just now switched to macbook and while running python in vs code i get
/usr/local/bin/python3 "/Users/rohitraaj/Documents/python vs/2nd.py"
File "<stdin>", line 1
/usr/local/bin/python3 "/Users/rohitraaj/Documents/python vs/2nd.py"
^
SyntaxError: invalid syntax
..how to solve this anyone please?
i tried finding the solution but was not able to get anything..
expecting that if someone might have encountered the same problem than they can help or if anyone can help to fix this.

Modulenotefounderror; No module name cplex

Im working on my Mac and I just fixed the script.
Then I wanted to make an edit and no nothing seem to work anymore.
I get the error message;
Traceback (most recent call last):
File "lu.py", line 1, in
import cplex
ModuleNotFoundError: No module named 'cplex'
I did not made the script and my knowledge about python is not much
When I want to start the script I use
terminal -- cd (file location) pyzton3 lu.py
Anyone who can help me with this problem?
This happens when the Python interpreter cannot find the CPLEX installation.
Usually this can be fixed by setting the PYTHONPATH variable correctly. Make sure that this variable contains the CPLEX Python libraries.
Assuming you are on Linux, you can do the following:
Find the CPLEX (or COS) installation folder.
Assuming this is /path/to/COS then you should have folder /path/to/COS/cplex/python/ and in that folder different sub-directories that correspond to different Python versions.
Assuming you are running Python 3.6, execute the following in your shell: export PYTHONPATH="$PYTHONPATH:/path/to/COS/cplex/python/3.6/x86-64_linux" and then execute your script as before in the same terminal.

Illegal Instruction 4 (Made a mess of python installation, no idea what I'm doing)

I am inexperienced with bash, python, and simply a lot of the basics/fundamentals some might take knowledge of for granted. I am using macOS 10.7.5. After installing numpy but getting error messages when importing in IDLE, I decided to reinstall python 3.7, but am getting several error messages now.
Some time ago, I installed python 3.7 from the python website, and it worked just fine. However, I had a great deal of trouble installing packages. The final straw was when I "successfully" installed numpy, but then I got a string of error messages when trying to import it in IDLE. I decided to try to re-install python, so I deleted python 3.7 and re-installed the same version from the same place.
However, when I tried typing "python3" in the Terminal, I got: "Segmentation Fault: 11". I researched it and understood that it had to do something with memory, so I must have uninstalled/installed wrong. However, I tried typing "python3" again, and got "Illegal Instruction: 4". After several tries, this is the only message I get anymore, and the segmentation fault does not appear.
I have no idea what I'm doing, and I don't know where to start. All I really know is that I've made a mess of the situation. I realize the solution might appear obvious, but I am completely inexperienced and in the dark right now. Thank you for reading this, I hope I can learn from you.
(Please ask for any and all information you might need, as I also don't know what exactly you might want to know.)
EDIT:
I realized when I re-installed Python, I had installed the macOS 10.9+ version. I uninstalled it and installed the correct version (10.6+). IDLE works and so does pip, but now I am getting the original error when I try to import numpy.
This is what I get:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import numpy
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/__init__.py", line 148, in <module>
from . import fft
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/fft/__init__.py", line 6, in <module>
from .fftpack import *
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/fft/fftpack.py", line 44, in <module>
from . import fftpack_lite as fftpack
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/fft/fftpack_lite.cpython-37m-darwin.so, 2): Symbol not found: ___sincos_stret
Referenced from: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/fft/fftpack_lite.cpython-37m-darwin.so
Expected in: /usr/lib/libSystem.B.dylib
in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/fft/fftpack_lite.cpython-37m-darwin.so```

File path wrong in PyCharm Python Console

I'm a beginner of Python and I want to run a python3 script in PyCharm Python Console, but it raise an error below:
>>> /Users/mymac/Documents/Python/test.py
File "<input>", line1
/Users/mymac/Documents/Python/test.py
^
SyntaxError: invalid syntax
I don't know what's wrong the file path is, how can I solve the problem?
use execfile('/Users/mymac/Documents/Python/test.py'). You are trying to run a python file like an executable. On top of that you are doing it in python interpreter.
Use python's execfile routine to call a file from interpreter or use python test.py to run it from the terminal.
I recognized that the answer I accepted ahead wasn't a perfect method, cause function execfile has been deleted in Python3, the alternative method is using open like:
>>> with open ('/Users/mymac/Documents/Python/test.py', 'r') as f:
... exec(f.read())
...
Still thanks for guys who helped me!
This could be several things. Have you set your environmental correctly? You can test this by cmd: python it should return Python 3.6.4 if that is your current version. If not then head over to tutorialsPoint for how to correctly set up your path.
If that is correctly configured, then have you selected an interpreter in PyCharm. If not, File --> Settings --> Project: Network --> Project Interpreter. Select your python installation path.
Another thing to note is that I suspect you mean to use the terminal instead of the python console.
Then in PyCharms terminal section, python test.py.

PyInstaller giving me a syntax error

UPDATE: Actually, now I have checked, and PyInstaller is saying Invalid Syntax for EVERY script I have, even ones that I have previously packaged with PyInstaller without any issues. I uninstalled and reinstalled PyInstaller, but it's still having the same problem. Is PyInstaller not compatible with Python 3.5.1? That's the only thing I can think of that I might have updated between now and when everything was working fine
Original Question: I'm sure there is a really simple and stupid answer for what I'm doing wrong, because I can't seem to find any other cases of people having this problem.
I have a script I want to package into a standalone executable. In the past, I have used PyInstaller with minimal hassle. Py2exe and cx_freeze have never worked for me. I'm using Python version 3.5.1 and PyInstaller version 3.2, which I believe is the current version since I just uninstalled and reinstalled.
The command I am trying to use is so simple I feel like an idiot for having trouble.
pyinstaller --onefile myscript.py
File "<stdin>", line 1
pyinstaller --onefile myscript.py
SyntaxError: invalid syntax
It's giving a generic SyntaxError: invalid syntax even though that is the exact command straight from the PyInstaller docs.
To be sure, I also tried to include the entire path to my script in the command, added and took out quotation marks, and tried every variation I could think of but it gives me the same syntax error every time.
I'm pretty much a beginner, so any really advanced fixes will go over my head. But like I said, I assume it's something silly I've missed. Thanks in advance.
The syntax error is caused by your command itself, not by the code it calls.
This part is very indicative:
File "<stdin>", line 1
pyinstaller --onefile myscript.py
You actually tried to run that command in a Python shell.
But it is not Python code. You should run it in a usual shell (cli.exe, bash, …)
Run It In CMD
Why are you running it in python shell? It's a problem with python syntax because it is not even defined.
>>> pyinstaller --onefile myscript.py
And, by the way. You are not even importing the PyInstaller module.
Run this line on your CMD:
pyinstaller --onefile filename.py
Ensure your script doesn't has any syntax errors. If it's so, then pyinstaller will rethrow the exception and this could be one of the reason.

Resources