0

I'm actually trying to import sacrebleu, but sacrebleu uses portalocker, and I get the following error (after it tries to import portalocker):


  File “run.py”, line 52, in <module>
    import sacrebleu
  File “/Users/username/miniconda3/envs/local_nmt/lib/python3.5/site-packages/sacrebleu/__init__.py”, line 21, in <module>
    from .utils import smart_open, SACREBLEU_DIR, download_test_set
  File “/Users/username/miniconda3/envs/local_nmt/lib/python3.5/site-packages/sacrebleu/utils.py”, line 8, in <module>
    import portalocker
  File “/Users/username/miniconda3/envs/local_nmt/lib/python3.5/site-packages/portalocker/__init__.py”, line 41
    LOCK_EX: constants.LockFlags = constants.LockFlags.EXCLUSIVE
           ^
SyntaxError: invalid syntax

Not sure what's going on here — does anyone have any insight? Let me know if there's any additional context that might be helpful!

Edit: Python version is 3.7.9!

ecataluna
  • 47
  • 6
  • It looks like you're getting a syntax error on an expression that contains a type hint annotation, which is a python 3 only feature. Are you using python 2 when you should be using python 3? – Jon Deaton Feb 02 '21 at 19:21
  • 1
    Variable annotations are a relatively new addition (Python 3.6), compared to function annotations (Python 3.0). – chepner Feb 02 '21 at 19:28
  • add the output of `python --version`, `python3 --version`, `which python`, `which python3` to your question please, and of course the command line with which you are running the file where you import sacrebleu from. – TheEagle Feb 02 '21 at 19:29
  • Thanks! Added an edit/clarification — I'm using Python 3.7.9! Also edited to include the full error: – ecataluna Feb 02 '21 at 20:37
  • I don't get it @chepner - Why did you close this? I don't see that it has anything to do with the linked "duplicate". The OP is seeing this error with Python 3.7.9. There was some guessing that this might be due to the lack of support for type hints in 2.X IF that's what the OP was using. This turned out not to be the case. Knowing what a "variable annotation" is, I don't believe is going to explain to the OP why they get an error installing a package on some Python 3.X installs and not on others. I confirmed that this is not the error you get if you try to install the package on 2.X. – CryptoFool Feb 03 '21 at 01:59
  • @Steve They may think they are using Python 3.7, but they aren't: look at the traceback. It refers to a 3.5 install. – chepner Feb 03 '21 at 12:49
  • @chepner - Ok, good catch then. If it were me, I'd have made the comment as to why the the duplicate question applied to the current issue a little more clear. Thanks for the explanation. – CryptoFool Feb 03 '21 at 15:27

1 Answers1

0

This problem isn't universal, nor even universal for Macs, as it installs correctly for me:

Collecting sacrebleu
  Downloading sacrebleu-1.5.0-py3-none-any.whl (65 kB)
     |████████████████████████████████| 65 kB 2.5 MB/s
Collecting portalocker
  Downloading portalocker-2.2.0-py2.py3-none-any.whl (15 kB)
Installing collected packages: portalocker, sacrebleu
Successfully installed portalocker-2.2.0 sacrebleu-1.5.0

This was installed into a test virtualenv. I'm running MacOS 10.15.7 and Python 3.7.3.

What version of Python are you running? Might you be running Python 2.X? That would quite possibly explain the problem as many packages have stopped supporting 2.X.

Do you use virtual environments? If so, have you tried installing into a fresh one?

UPDATE: I tried installing this package under Python 2.7.16. It fails to install, but gives me a different error than the one you're getting.

CryptoFool
  • 21,719
  • 5
  • 26
  • 44
  • Thanks! it's definitely not universal — I'm trying to figure out why it works for some people but not for others. I'm running this on Python 3.7.9! This works on virtual environments/on Azure, but it doesn't work on my local computer/is also failing for some other people, but not everyone! – ecataluna Feb 02 '21 at 20:36
  • @ecataluna Look at your traceback. You are actually running Python 3.5. – chepner Feb 03 '21 at 12:50