Python3的PIP安装了Python2脚本,如何使其在Python3环境运行?
ever2simple to Run in Python 3 Environment Got it, let's work through this issue together. That SyntaxError about missing parentheses in print is a dead giveaway—this script was built exclusively for Python 2, where print was a statement instead of a function (which requires parentheses in Python 3). Here are three reliable ways to get it working on your Windows 10 Python 3 setup:
1. Use Python's Official 2to3 Tool to Auto-Convert Syntax
This is the most straightforward method since it handles most Python 2 → 3 syntax changes automatically:
- First, locate the source code folder of
ever2simple. Since you installed it via Miniconda, it's probably in...\Miniconda3\Lib\site-packages\ever2simple(look for a folder with.pyfiles inside). - Open your Command Prompt or Anaconda Prompt, navigate to that folder with:
cd "C:\Path\To\Miniconda3\Lib\site-packages\ever2simple" - Run the
2to3tool with the-wflag to write changes directly to the files:
This will update all2to3 -w .printstatements to use parentheses, convertxrangetorange, fix exception handling syntax (likeexcept Error, e→except Error as e), and more. - After conversion, try running
ever2simple.exeagain—it should now work with Python 3.
2. Create a Python 2 Virtual Environment (No Code Changes Needed)
If you'd rather not modify the script, you can run it in a dedicated Python 2 environment (note: Python 2 is no longer supported, so use this only for legacy scripts):
- Create a new conda environment with Python 2.7:
conda create -n py27 python=2.7 - Activate the environment:
conda activate py27 - Install
ever2simplein this environment:pip install -U ever2simple - Run the script from this activated environment—it will use Python 2 and avoid the syntax error entirely.
3. Manually Update the Script's Syntax
If you prefer to tweak the code yourself (great for learning or small scripts):
- Find all
.pyfiles in theever2simplesource folder (mentioned in method 1). - Open each file and replace every Python 2-style
printstatement:- Change
print 'File does not exist: %s' % filepath→print('File does not exist: %s' % filepath) - Replace any other
printstatements without parentheses (e.g.,print "Hello"→print("Hello"))
- Change
- Check for other Python 2-specific syntax:
- Replace
except Exception, e→except Exception as e - Replace
xrange()→range()
- Replace
- Save all changes, then run the script again.
内容的提问来源于stack exchange,提问作者trebi

