I'm trying to use Jupyter-book to create automatical PDF from my output, but after installing it using the 'pip install -U jupyter-book' command (which runs successfully), it doesn't recognize jupyter-book when I try to run a command:
Input:
jupyter_book create Jupyter_Book_Name
Output:
SyntaxError: invalid syntax (Temp/ipykernel_16888/3781613275.py, line 1)
File "C:\Users\MAXIME~1.DUS\AppData\Local\Temp/ipykernel_16888/3781613275.py", line 1
jupyter_book create Jupyter_Book_Name
^
SyntaxError: invalid syntax
I already try to add the init jupyter_book function in the sys.path but I get the same error, and the error arises for any command. I am working in Python 3.9.7 with Jupyter Notebook in Visual Studio Code on Windows 10.
Thank you in advance, any help would really help me.
Looks like you're confusing a shell (bash / ...) with a Python REPL.
You're running a shell command in a Python interpreter, a bit like if you try to start Python by typing python inside a Python interpreter:
$ python # Here I'm in bash, I run Python
Python 3.9.7 (default, Sep 3 2021, 06:18:44)
>>> python # Here I'm in the Python interpreter
# typing python again...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'python' is not defined
# Yup, calling `python` here make no sense, Python looks for a variable
# named `python` not a program named `python`, and won't find it.
So get out of a Python interpreter, find a shell (depending on your OS), and run the command again.
Oh while I'm here, it's probably not:
jupyter_book create Jupyter_Book_Name
but:
jupyter-book create Jupyter_Book_Name
Related
I've tweaked a copy of one of the Nsight Systems report scripts (gpukernsum), and I now want to run it myself. So, I write:
./gpukernsum.py report.sqlite
This doesn't work; I get:
ERROR: Script 'gpukernsum.py' encountered an internal error.
$ ./gpukernsum.py report.sqlite
File "./gpukernsum.py", line 40
"""
^
SyntaxError: invalid syntax
I know this is because f"""whatever""" is Python-3 syntax, so I change the script's hash-bang line from:
#!/usr/bin/env python
to:
#!/usr/bin/env python3
and now I get:
$ ./gpukernsum.py report.sqlite
Traceback (most recent call last):
File "/path/to/./gpukernsum.py", line 7, in <module>
import nsysstats
ModuleNotFoundError: No module named 'nsysstats'
So I added the relevant directory to the lookup path:
export PYTHONPATH="$PYTHONPATH:/opt/nvidia/nsight-systems/2022.1.1/host-linux-x64/python/lib"
and now I get:
$ ./gpukernsum.py report.sqlite
near "WITH": syntax error
... and I'm stuck. The relevant area of the code is:
and not a percentage of the application wall or CPU execution time.
"""
query_stub = """
WITH
summary AS (
SELECT
coalesce({NAME_COL_NAME}, demangledName) AS nameId,
i.e. the "WITH" is part of a string literal which is an SQL query. So, what's the problem? Is Python complaining? Is sqlite complaining?
Note:
Nsight Systems 2022.1.1
CentOS 7
I'm using the original gpukernsum.py code - I have not made any changes to it (other than as described above).
My system has Python 3.9.1 for python3.
A workaround answer:
Nsight Systems bundles its own version of Python, with lib and bin directories.
If you run your script with this specific version, having set PYTHONPATH as described in your question - then the script will work. It's what Nsight itself does, after all.
Noob question here, Neovim throws an error when running a script using input() in the command-line window, while the same script runs in vim 8.0. eg
print('Enter your name:')
myName = input()
:! python % <- ex command used
Nvim output:
myName: Traceback (most recent call last):
File "x.py", line 2, in <module>
myName = input()
EOFError: EOF when reading a line
shell returned 1
I prefer the way neovim runs it's scripts in it's own bottom window as opposed to vim outputting to the command line, but I have to switch to vim for any scripts using input().
Is there a nvim.init setting or a different command I can use to succeed here, or is this a known flaw in neovim? I'm on wsl using the latest vim and nvim.
I am not sure why you're getting this error. But, since you are using neovim, have you tried using the built-in terminal emulator? The below command can be used to run the program within newovim in a new split window:
:vsplit term://python3 %
python3 is the name of program, which can be substituted with any other program. Where % is the current file's path. See :h terminal-start for more information.
The same can be done using Vim (8.0 or above) by using the command:
:term python3 %
this will again open a new split for the program running. See :h terminal for more information.
A further optimization to the workflow would be to add a filetype specific mapping. In our case that would be(unix like systems) in ~/.vim/after/ftplugin/python.vim
nnoremap <leader>r :vsplit term://python3 %<cr>
This is the resulting notice of entering "python --version"
Traceback (most recent call last): File "", line 1, in NameError: name 'python' is not defined
I have tried Python 2.7 and 3.6 shell as well as my terminal but cannot seem to figure out whats wrong.
Eventually, I am trying to get pip.
You habe to start a normal command line, not the python shell if you want that the command python --version works.
If you want to use the python shell you have to type
import sys
sys.version_info
I installed Python 3.4.0 64 bit and gdal file release-1400-x64-gdal-1-11-1-mapserver-6-4-1.zip from http://www.gisinternals.com/release.php. I found the binding from http://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal and the filename is GDAL-1.11.2-cp34-none-win_amd64. I successfully install these files and import gdal. However, when I run the following command within the Python IDE to merge files 1 2 and 3, I got an error
>>> gdal_merge.py -o out.tif 1.tif 2.tif 3.tif
File "<console>", line 1
gdal_merge.py -o out.tif 1.tif 2.tif 3.tif
^
SyntaxError: invalid syntax
I specifically check to see if I can import gdal_merge as below
>>> import gdal_merge
and it was ok.
I appreciate if anybody could help with this issue.
gdal_merge.py is part of the GDAL utilities which are executed from the command line, not from within a Python IDE or another Python script.
Just open a command line (cmd) and type:
python gdal_merge.py -o out.tif 1.tif 2.tif 3.tif
Depending on your environment variables and whether you included GDAL in your Path variable you might need to specificy the full path to gdal_merge.py and/or can leave out python at the beginning of the call.
I am in the python command line (using python 2.7), and trying to run a Python script. My operating system is Windows 7. I have set my directory to the folder containing all of my scripts, using:
os.chdir("location").
os.getcwd() returns this location.
When I type:
python myscript.py
I get this error:
File "<stdin>", line 1
python myscript.py
^
SyntaxError: invalid syntax.
What have I done wrong?
The first uncommented line of the script I'm trying to run:
from game import GameStateData
It sounds like you're trying to run your script from within Python. That's not how it works. If you want to run myscript.py, you need to do it from a system command prompt, not from inside the Python interpreter. (For instance, by choosing "Command Prompt" from your start menu. I think it's usually under "Accessories" or something like that.) From there you'll need to change to the directory where your scripts are by using the CD command.
Based on the additional information you have provided it does look like you are issuing the command inside of Python.
EDIT: Maybe part of the confusion comes from the term command line. You are at the command line in both the "Windows command" shell, and also when you are inside the "Python shell".
This is what I get in the command line when inside the Python shell:
D:\Users\blabla \Desktop>python
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> python testit.py
File "<stdin>", line 1
python testit.py
^
SyntaxError: invalid syntax
>>>
Or this:
>>> os.chdir("..")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'os' is not defined
>>>
My suggestion would be to open a Windows command shell window with the cmd command and then issue your python myscript.py from there.
For more help it would be helpful to see your code, at least the first few lines where the error occurs and some certainty as to where the python command is being issued.
As the other answers indicate, you are probably in the Python shell unintentionally. But if you really do want to run your script from there, try execfile("myscript.py")
on windows shell run echo %PATH%, and check if your .py is under any of the paths.