I'm using Jupyter Notebooks from VSCode.
I'm having issues starting my Python (Sagemath) Kernel. The error text (when running the cell in VSCode) is as follows:
Failed to start the Kernel.
unknown option --python
usage: /root/anaconda3/envs/sage/bin/python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.
View Jupyter log for further details.
This is a snippet from the log file:
warn 16:18:12.373: Kernel Error, context = start [ap [Error]: The kernel died. Error: unknown option --python
usage: /root/anaconda3/envs/sage/bin/python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.... View Jupyter [log](command:jupyter.viewOutput) for further details.
at ChildProcess.<anonymous> (/root/.vscode-server/extensions/ms-toolsai.jupyter-2023.1.2000312134/out/extension.node.js:17:102857)
at ChildProcess.emit (node:events:538:35)
at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)] {
category: 'kerneldied',
kernelConnectionMetadata: Zd {
kind: 'startUsingPythonInterpreter',
kernelSpec: {
specFile: '/root/anaconda3/envs/sage/share/jupyter/kernels/sagemath/kernel.json',
interpreterPath: '/root/anaconda3/envs/sage/bin/python',
isRegisteredByVSC: 'registeredByNewVersionOfExtForCustomKernelSpec',
name: 'pythonjvsc74a57bd0fbfe4b38fd9276f8fd065521985c9d949b01305ee70753a4e78b421b898ddb3e',
argv: [Array],
language: 'sage',
executable: '/root/anaconda3/envs/sage/bin/sage',
display_name: 'SageMath 9.7',
metadata: [Object]
},
interpreter: {
id: '/root/anaconda3/envs/sage/bin/python',
sysPrefix: '/root/anaconda3/envs/sage',
envPath: [f],
displayPath: [Object],
envName: 'sage',
displayName: 'sage',
envType: 'Conda',
version: [Object],
uri: [f]
},
id: '.jvsc74a57bd0fbfe4b38fd9276f8fd065521985c9d949b01305ee70753a4e78b421b898ddb3e#sagemath./root/anaconda3/envs/sage/python././root/anaconda3/envs/sage/bin/sage#--python#-m#sage.repl.ipython_kernel#-f#{connection_file}'
},
exitCode: 2,
stdErr: 'unknown option --python\n' +
'usage: /root/anaconda3/envs/sage/bin/python [option] ... [-c cmd | -m mod | file | -] [arg] ...\n' +
"Try `python -h' for more information.\n"
}
error 16:18:12.591: Failed to get activated conda env variables from Python for /root/anaconda3/envs/sage/bin/python
info 16:18:12.595: Process Execution: > ~/anaconda3/envs/sage/bin/python -c "import ipykernel;print('6af208d0-cb9c-427f-b937-ff563e17efdf')"
> ~/anaconda3/envs/sage/bin/python -c "import ipykernel;print('6af208d0-cb9c-427f-b937-ff563e17efdf')"
info 16:18:12.763: Dispose Kernel '/path/to/ipynb' associated with '/same/path/to/ipynb'
Took a look at other similar kernel start problems, but the errors thrown were different (NOT one with 'unknown option --python', and the solutions implemented obviously did not work.
Please let me know if you need any more information to help!
Solved - Edit the kernel.json file of the kernel and remove the --python option
Related
I'm trying to create a virtual environment, but when I input the mkvirtualenv command this happens
PS C:\Users\jorel\Documents> mkvirtualenv '.\Trading Bot\
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
usage: virtualenv [--version] [--with-traceback] [-v | -q] [--read-only-app-data] [--app-data APP_DATA] [--reset-app-data] [--upgrade-embed-wheels] [--discovery {builtin}] [-p py] [--try-first-with py_exe]
[--creator {builtin,cpython3-win,venv}] [--seeder {app-data,pip}] [--no-seed] [--activators comma_sep_list] [--clear] [--no-vcs-ignore] [--system-site-packages] [--copies] [--no-download | --download]
[--extra-search-dir d [d ...]] [--pip version] [--setuptools version] [--wheel version] [--no-pip] [--no-setuptools] [--no-wheel] [--no-periodic-update] [--symlink-app-data] [--prompt prompt] [-h]
dest
virtualenv: error: unrecognized arguments: Bot"
SystemExit: 2
I was expecting something like this
(Trading Bot) PS C:\Users\jorel\Documents>
Can you try :
python -m venv venv
source venv/bin/activate
I create my virtual environment like this
My playbook runs fine when conda is not installed but runs into the following error if it is installed:
TASK [Ensure `base` environment uses Python 3.9] ********************************
fatal: [my_machine]: FAILED! => {"msg": "The conditional check ''not found' in command_output.stdout' failed. The error was: error while evaluating conditional ('not found' in command_output.stdout): 'dict object' has no attribute 'stdout'\n\nThe error appears to be in '/Users/ansible/tasks/install-miniconda.yaml': line 25, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Ensure base environment uses Python 3.9\n ^ here\n"}
If conda is found to be installed, it skips tasks previous to this step and fails here.
- import_tasks: tasks/check-command.yaml
vars:
command: conda
- import_tasks: tasks/install-miniconda.yaml
vars:
install_dir: "~/"
when: "'not found' in command_output.stdout"
---
- name: Download miniconda
ansible.builtin.get_url:
url: https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
dest: "{{ install_dir }}miniconda.sh"
mode: 0644
- name: Setup .local/opt
ansible.builtin.file:
path: ~/.local/opt
state: directory
mode: u=rwx,go=rx
- name: Install miniconda # noqa no-changed-when
ansible.builtin.shell: |
/bin/bash {{ install_dir }}miniconda.sh -b -p ~/.local/opt/miniconda3
. ~/.local/opt/miniconda3/bin/activate
conda init bash
- import_tasks: login-shell.yaml
vars:
name: Check `base` environment Python version
command: python --version
- name: Ensure `base` environment uses Python 3.9
ansible.builtin.command: conda install -n base python=3.9
when: 'command_output.stdout is not regex("^Python 3.9.\d+$")'
- name: Cleanup conda install script
ansible.builtin.file:
path: "{{ install_dir }}miniconda.sh"
state: absent
There are more problems:
The error is: 'dict object' has no attribute 'stdout'. Take a look at the dictionary and fix it.
For some reason, Python2 writes the version to stderr. For example,
- command: python --version
register: command_output
- debug:
var: command_output
gives
TASK [debug] *****************************************************
ok: [localhost] =>
command_output:
ansible_facts:
discovered_interpreter_python: /usr/bin/python3
changed: true
cmd:
- python
- --version
delta: '0:00:00.004342'
end: '2022-08-12 22:51:57.467916'
failed: false
msg: ''
rc: 0
start: '2022-08-12 22:51:57.463574'
stderr: Python 2.7.18
stderr_lines:
- Python 2.7.18
stdout: ''
stdout_lines: []
As a result, the condition below will be always true
- debug:
msg: Run conda install -n base python=3.9
when: 'command_output.stdout is not regex('^Python 3.9.\d+$')'
Fix it by using shell and redirecting stderr to stdout. For example,
- shell: python --version 2>&1
register: command_output
- debug:
var: command_output
gives
TASK [debug] *****************************************************
ok: [localhost] =>
command_output:
changed: true
cmd: python --version 2>&1
delta: '0:00:00.004157'
end: '2022-08-12 22:57:10.841659'
failed: false
msg: ''
rc: 0
start: '2022-08-12 22:57:10.837502'
stderr: ''
stderr_lines: []
stdout: Python 2.7.18
stdout_lines:
- Python 2.7.18
Use version to test the versions. For example,
- name: Ensure base environment uses Python 3.9
debug:
msg: Run conda install -n base python=3.9
when: python_version is version('3.9', '<')
vars:
python_version: "{{ command_output.stdout.split()|last }}"
Generally, there might be more versions of Python installed in the system. Use the variable ansible_python_version if you want to find out the version Ansible is using. Otherwise, make sure the path in the command python --version is what you want.
I am using the command in cmd:
py -3.7.6 -m googlesamples.assistant.grpc.audio_helpers
This does not work. I get a response:
Unknown option: -3
usage: C:\Users\Yakuza\AppData\Local\Programs\Python\Python39\python.exe [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.
============================
How to specify version for this to work?
Sorry for the stupid question, I'm just tired, but I want to finish
You cannot specify 3.7.6 using the Python Launcher for Windows it only recognizes the first two digits, major.minor. You could use a shebang line in the file with the full path. Or specify the path to the version you want - C:\path\to\pythonV3.7.6\python.exe -m ...
I have a Pipfile with such script
[script]
tests = "pytest --cov-fail-under=40 tests/"
I wan to make the cov-fail-under parameter value depend on a env var. Out of the Pipfile script, the following command does the job:
pytest --cov-fail-under=$( case $VARin true ) echo 40 ;; * ) echo 80 ;; esac ) tests/
But when executed with the pipenv run tests the bash condition is shown as a string producing the following error:
ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: argument --cov-fail-under: invalid validate_fail_under value: '$('
Is there any workaround to solve this?
You can spawn a shell with sh -c:
Pipfile
[scripts]
tests = "sh -c '[ \"${VAR}\" = \"true\" ] && mincov=40 ; pytest --cov-fail-under=\"${mincov:-80}\" tests'"
I have this playbook:
---
- hosts: all
become: yes
become_user: root
gather_facts: no
pre_tasks:
- name: 'install python2'
raw: sudo apt-get -y install python-simplejson
roles:
- git
...
Sometimes, it works perfectly fine and sometimes it gives me this error:
==> default: Running provisioner: ansible...
default: Running ansible-playbook...
PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -i '/var/www/test/.vagrant/machines/default/virtualbox/private_key' -o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --connection=ssh --timeout=30 --extra-vars="ansible_ssh_user='ubuntu'" --limit="all" --inventory-file=ansible/hosts/hosts_linux.txt -v ansible/site.yml
Using /etc/ansible/ansible.cfg as config file
PLAY ***************************************************************************
TASK [install python2] *********************************************************
fatal: [10.0.11.44]: FAILED! => {"changed": false, "failed": true, "rc": 255, "stderr": "", "stdout": "", "stdout_lines": []}
PLAY RECAP *********************************************************************
10.0.11.44 : ok=0 changed=0 unreachable=0 failed=1
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
I am wondering why do I get this error and what does it mean? There is no output on the error and the exactly same code works if I try this many times. It makes no sense. Why is ansible failing to install python?
According to your comments, the problem is with ssh. You can create your own ansible.cfg file in your current working directory and supply openssh options directly as described here: open-ssh options
I suggest you try:
[defaults]
host_key_checking = False
And also during your playbook run, you can manually specify which ssh key to use like:
ansible-playbook --private-key /path/to/ssh_key ...
Finally, make sure there is no IP conflict, because your server's ssh fingerprint should not change. Try manually ssh'ing a few times as well.