Hi Everyone, I am working on a pants 1.9.0 project...
# general
e
Hi Everyone, I am working on a pants 1.9.0 project that uses python 2.7. Upon running any pants comments i get this error
Copy code
./pants build rapidfire::
/Users/aminghadersohi/.cache/pants/setup/bootstrap-Darwin-x86_64/1.10.0/lib/python2.7/site-packages/OpenSSL/crypto.py:12: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in a future release.
  from cryptography import x509
timestamp: 2021-01-14T20:56:24.152463
Exception caught: (exceptions.UnicodeDecodeError) (backtrace omitted)
Exception message: 'ascii' codec can't decode byte 0xe2 in position 4: ordinal not in range(128)
h
Hi Amin, that is a very old version of Pants, not sure we'll be able to reproduce this, but some information would be useful: Did this work for you until recently? Did anything change in your system that may have caused this to stop working?
And can you run this in that interpreter, and post what it returns?
Copy code
>>> import locale
>>> locale.getpreferredencoding()
e
Hi Benjy! Thank you for your help 🙂 Here is what I get
Copy code
~  python

WARNING: Python 2.7 is not recommended.
This version is included in macOS for compatibility with legacy software.
Future versions of macOS will not include Python 2.7.
Instead, it is recommended that you transition to using 'python3' from within Terminal.

Python 2.7.16 (default, Jun  5 2020, 22:59:21)
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getpreferredencoding()
'UTF-8'
>>>
So this is a new laptop. My old laptop had a problem and I had to switch. Its pretty basic, nothing special installed other than java, scala, and some brew formulae. I mainly use intelij and gradle
I could blow away all the brew stuff and start from scratch
that didnt work either
h
OK, UTF-8 is a good start
e
🙂 but still no luck
i have given up hope already
h
We'll figure it out, no need to give up hope just yet...
Let's try this: in that interpreter do
pip install pyopenssl==17.3.0
and then in a repl do
from cryptography import x509
What does that do?
You can do it in a virtualenv if you don't want to pollute the interpreter's base environment
So something like:
Copy code
$ path/to/interpreter/2.7.16/bin/pip install virtualenv
$ path/to/interpreter/2.7.16/bin/virtualenv /tmp/venv
$ source /tmp/venv/bin/activate
$ python2
Python 2.7.16 (default, May 19 2020, 16:23:05) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from cryptography import x509
e
Copy code
✘  ~/github/TinderBackend/palo   master ±  python -m pip --version
pip 20.3.3 from /Users/aminghadersohi/Library/Python/2.7/lib/python/site-packages/pip (python 2.7)
 ~/github/TinderBackend/palo   master ±  python -m pip install pyopenssl==17.3.0
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at <https://pip.pypa.io/en/latest/development/release-process/#python-2-support> pip 21.0 will remove support for this functionality.
Defaulting to user installation because normal site-packages is not writeable
Collecting pyopenssl==17.3.0
  Using cached pyOpenSSL-17.3.0-py2.py3-none-any.whl (51 kB)
Requirement already satisfied: six>=1.5.2 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from pyopenssl==17.3.0) (1.12.0)
Requirement already satisfied: cryptography>=1.9 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from pyopenssl==17.3.0) (2.6.1)
Requirement already satisfied: asn1crypto>=0.21.0 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from cryptography>=1.9->pyopenssl==17.3.0) (0.24.0)
Requirement already satisfied: cffi!=1.11.3,>=1.8 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from cryptography>=1.9->pyopenssl==17.3.0) (1.12.2)
Requirement already satisfied: enum34 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from cryptography>=1.9->pyopenssl==17.3.0) (1.1.6)
Requirement already satisfied: ipaddress in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from cryptography>=1.9->pyopenssl==17.3.0) (1.0.22)
Requirement already satisfied: pycparser in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from cffi!=1.11.3,>=1.8->cryptography>=1.9->pyopenssl==17.3.0) (2.19)
Installing collected packages: pyopenssl
Successfully installed pyopenssl-17.3.0
 ~/github/TinderBackend/palo   master ±  python

WARNING: Python 2.7 is not recommended.
This version is included in macOS for compatibility with legacy software.
Future versions of macOS will not include Python 2.7.
Instead, it is recommended that you transition to using 'python3' from within Terminal.

Python 2.7.16 (default, Jun  5 2020, 22:59:21)
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from cryptography import x509
>>>
running it globally worked
super weird bug of some sort. But thank you for your help!
h
How feasible would it be for y'all to upgrade to a more recent version of Pants? Starting in 1.16, Pants runs with Python 3 instead of Python 2 and generally there's fewer Unicode issues like this
h
@echoing-lock-18813 ☝️
e
I just tried 1.16.0 and it still installs python 2.7 and runs into same issue
I think i need to modify the pants file too
Screen Shot 2021-01-19 at 12.48.30 PM.png
Screen Shot 2021-01-19 at 12.48.50 PM.png
✘  ~/github/TinderBackend/palo   master ±  rm -rf .pants.d && rm -rf .idea && rm -rf ~/.cache/pants ~/github/TinderBackend/palo   master ±  ./pants % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 122 100 122 0 0 1370 0 -- -- -- -- -- -- 1370 100 281 100 281 0 0 1156 0 -- -- -- -- -- -- 1156 0 0 0 0 0 0 0 0 -- -- -- -- -- -- 0 100 2576k 100 2576k 0 0 4142k 0 -- -- -- -- -- -- 4142k Using base prefix '/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8' /Users/aminghadersohi/.cache/pants/setup/bootstrap-Darwin-x86_64/virtualenv-15.2.0/virtualenv.py1047 DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses import imp New python executable in /Users/aminghadersohi/.cache/pants/setup/bootstrap-Darwin-x86_64/pants.67UB9s/install/bin/python3 Also creating executable in /Users/aminghadersohi/.cache/pants/setup/bootstrap-Darwin-x86_64/pants.67UB9s/install/bin/python Traceback (most recent call last): File "/Users/aminghadersohi/.cache/pants/setup/bootstrap-Darwin-x86_64/virtualenv-15.2.0/virtualenv.py", line 2349, in <module> main() File "/Users/aminghadersohi/.cache/pants/setup/bootstrap-Darwin-x86_64/virtualenv-15.2.0/virtualenv.py", line 703, in main create_environment(home_dir, File "/Users/aminghadersohi/.cache/pants/setup/bootstrap-Darwin-x86_64/virtualenv-15.2.0/virtualenv.py", line 925, in create_environment py_executable = os.path.abspath(install_python( File "/Users/aminghadersohi/.cache/pants/setup/bootstrap-Darwin-x86_64/virtualenv-15.2.0/virtualenv.py", line 1342, in install_python shutil.copy(original_python, py_executable) UnboundLocalError: local variable 'original_python' referenced before assignment ./pants: line 105: /Users/aminghadersohi/.cache/pants/setup/bootstrap-Darwin-x86_64/1.16.0/bin/python: No such file or directory
h
It looks like that did run on python3?
e
looks like it did but the project files are huge and i am not a pants expert to migrate it to pants 1.16. Rip
h
I mean, you said above "I just tried 1.16.0 and it still installs python 2.7", but if I look at the stack trace it looks like it ran on python 3.8?
Note that your own code can still run on python 2.7, even if pants itself runs on python 3. So upgrading Pants shouldn't require any migration of your own code.
e
Oh yeah i tried at first with just bumping pants but then realized the pants script also has a hard coded ref to python2 so i changed that python3 and then i got the above output
h
gotcha
Hmmm, let me think about this one. Might need to do some googling.
e
yeah ive been on it, had to compile in CI hahah painful Thanks so much for any help