0

So basically, I am using a package online that requires the use of the shell in order to parse data. The line of code that needs to be sent to the shell is as follows:

python scripts/extract.py esm2_t33_650M_UR50D data/output.fasta data/output_esm --repr_layers 33 --include per_tok

Where extract.py contains a Python script that needs to be run.

In order to achieve this, I had to utilize the ! in the code cell in order to send the line of code to the shell.

However, running the code cell returned an invalid syntax error:

File "scripts/extract.py", line 79
    print(f"Read {args.fasta_file} with {len(dataset)} sequences")
                                                                ^
SyntaxError: invalid syntax

Looking online, it seemed this was caused by the f"" functionality not being available in Python 2.x versions. Which is weird since I am currently running Jupyter on Python 3.8.13.

So I checked the version of Python through the shell and realized it was still running on Python 2.7.17

How do I tell the shell explicitly to use Python 3.x interpreter and packages instead of 2.x? I was always under the assumption that the shell would use the same version of Python that Jupyter is running on.

Thank you!

3
  • Does stackoverflow.com/questions/60497198 answer your question? Commented Feb 17, 2023 at 1:58
  • Also, you aren't using Jupyter in the way it is meant. To run a Python script from inside a notebook, you'll have better support and features using %run magic, see here. In fact you can insure it even runs in the same namespace as the current notebook by adding the -i flag. So that any variables you've assigned in the current running notebook will be accessible by the script. This is very helpful when developing a script or debugging. About your assumption, see the second paragraph ... Commented Feb 17, 2023 at 16:01
  • <continued> here. Possible issues with where things run when using the exclamation point is also related to why you should now use the magic install commands if you ever install packages from inside your running notebook using pip or conda, see here. Commented Feb 17, 2023 at 16:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.