When I run the python file on the terminal, I get the following error:
python path/filename.py
Traceback (most recent call last):
File"/Users/xxx/Desktop/Python/test.py", line 5, in <module>
import pandas aspd
File"/Library/Frameworks/Python.framework/Version/3.8/lib/python 3.8/site-packages/pandas/_init__.py", line 13
missing_dependencies.append(f"{dependency}:{e}")
^
SyntaxError: invalid syntax
Why SyntaxError for pandas/init.py
that never fiddled with the contents?
What I don't know is that import pandas
on the Jupiter Notebook works fine.
The module path in the Jupiter Notebook is also Python 3.
I look forward to hearing from you.
Basic Information
OS:Mac
python 3.8
The process of getting an error
Install python environment in Anaconda → Install python 3.8 from official site because !pip could not be done in Jupiter notebook, install pandas, jupyter from terminal → Current status
June 7, 2020 Additional information
$python --version
Python 2.7.16
$python-c'import sys;print(sys.path)'
['', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Python/2.7/site-packages', '/System/Library/Frameworks/Python.frameworks/Version/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.frameworks/Version/2.7/Extras/lib/python/PyObjC']
python --version
points to Python 2.x, which was originally installed on the system.Perhaps the python3
command refers to the newly installed one.
So try running python3
, and pip
is probably also p3
.
If you want Python 3 series to start just by typing python
, you can create an alias for the shell command as such. (python
command itself points to Python 3 series, which can break what you expect to use Python 2 series.Enable Python 3 series only in your shell.) .
In other words, ~/.bash_profile
or ~/.zshenv
depending on your shell.
alias python='python'
Restart the shell by writing
However, I personally think that as the dependencies of various libraries become increasingly complicated, you may want to use Python's virtual environment instead of this method (this is where tastes and preferences are divided).
Incidentally, missing_dependencies.append(f"{dependency}:{e}")
gets SyntaxError because the syntax f"Honyara"
is new from Python 3.6 .Looking at this error, I guessed that the python
command probably pointed to the Python 2 series preinstalled on the Mac, so I asked the questioner to check the version.
© 2025 OneMinuteCode. All rights reserved.