Error detecting python version

Hi, I'm new here, trying to develop some plugins for a Marlin printer. I followed the instructions on the plugin tutorial. However, I am getting some errors when using the command "octoprint serve" that I don't know how to resolve. They all trace back to "ERROR - Error detecting python version." I am running WSL on Windows. Here are the error messages:

2019-07-09 16:28:48,525 - octoprint.environment - ERROR - Error detecting python version
Traceback (most recent call last):
  File "/mnt/c/OctoPrint/src/octoprint/environment.py", line 78, in _detect_python
    result["version"] = get_python_version_string()
  File "/mnt/c/OctoPrint/src/octoprint/util/version.py", line 126, in get_python_version_string
    version_string = python_version[:-1]
TypeError: 'function' object has no attribute '__getitem__'
2019-07-09 16:28:48,529 - octoprint.environment - ERROR - Error while detecting hardware environment
Traceback (most recent call last):
  File "/mnt/c/OctoPrint/src/octoprint/environment.py", line 105, in _detect_hardware
    cpu_freq = psutil.cpu_freq()
  File "/mnt/c/OctoPrint/venv/local/lib/python2.7/site-packages/psutil/__init__.py", line 1985, in cpu_freq
    ret = _psplatform.cpu_freq()
  File "/mnt/c/OctoPrint/venv/local/lib/python2.7/site-packages/psutil/_pslinux.py", line 698, in cpu_freq
    "can't find current frequency file")
NotImplementedError: can't find current frequency file
2019-07-09 16:28:48,537 - octoprint.environment - INFO - Detected environment is Python unknown under Linux (linux2). Details:
|  hardware:
|    cores: unknown
|    freq: unknown
|    ram: unknown
|  os:
|    id: linux
|    platform: linux2
|  python:
|    pip: 19.1.1
|    version: unknown
|    virtualenv: /mnt/c/OctoPrint/venv
2019-07-09 16:28:48,546 - octoprint.server - INFO - Reset webasset folder /home/tonypan/.octoprint/generated/webassets...
2019-07-09 16:28:48,550 - octoprint.server - INFO - Reset webasset folder /home/tonypan/.octoprint/generated/.webassets-cache...
2019-07-09 16:28:48,787 - octoprint.server - INFO - Shutting down intermediary server...
2019-07-09 16:28:49,270 - octoprint.server - INFO - Intermediary server shut down
2019-07-09 16:28:49,272 - octoprint.events - INFO - Processing startup event, this is our first event
2019-07-09 16:28:49,274 - octoprint.events - INFO - Adding 0 events to queue that were held back before startup event
2019-07-09 16:28:49,275 - octoprint.filemanager - INFO - Adding backlog items from all storage types to analysis queue...
2019-07-09 16:28:49,277 - octoprint.server.util.watchdog - INFO - Running initial scan on watched folder...
2019-07-09 16:28:49,279 - octoprint.filemanager - INFO - Added 0 items from storage type "local" to analysis queue
2019-07-09 16:28:49,280 - octoprint.server.util.watchdog - INFO - ... initial scan done.
2019-07-09 16:28:49,285 - octoprint.plugins.discovery - INFO - Registered OctoPrint instance on DESKTOP-BB020B0 for SSDP
2019-07-09 16:28:49,286 - octoprint.server - INFO - Listening on http://0.0.0.0:5000 and http://[::]:5000
2019-07-09 16:28:49,302 - octoprint.plugins.pluginmanager - INFO - Loaded plugin repository data from disk, was still valid
2019-07-09 16:28:49,517 - octoprint.plugins.pluginmanager - INFO - Loaded notice data from disk, was still valid
2019-07-09 16:28:50,472 - octoprint.util.pip - INFO - Using "/mnt/c/OctoPrint/venv/bin/python -m pip" as command to invoke pip
2019-07-09 16:28:50,473 - octoprint.util.pip - INFO - pip installs to /mnt/c/OctoPrint/venv/lib/python2.7/site-packages (writable -> yes), --user flag needed -> no, virtual env -> yes
2019-07-09 16:28:50,474 - octoprint.util.pip - INFO - ==> pip ok -> yes
2019-07-09 16:28:50,474 - octoprint.plugin - ERROR - Error while calling plugin softwareupdate
Traceback (most recent call last):
  File "/mnt/c/OctoPrint/src/octoprint/plugin/__init__.py", line 219, in call_plugin
    result = getattr(plugin, method)(*args, **kwargs)
  File "/mnt/c/OctoPrint/src/octoprint/plugins/softwareupdate/__init__.py", line 102, in on_after_startup
    self._check_environment()
  File "/mnt/c/OctoPrint/src/octoprint/plugins/softwareupdate/__init__.py", line 184, in _check_environment
    versions = dict(python=get_python_version_string(),
  File "/mnt/c/OctoPrint/src/octoprint/util/version.py", line 126, in get_python_version_string
    version_string = python_version[:-1]
TypeError: 'function' object has no attribute '__getitem__'

I'm curious to know what it's seeing myself:

/mnt/c/OctoPrint/venv/bin/activate
python --version

Thanks for your response! The python version inside the virtual environment is Python 2.7.15+

Hi!
It may be useful that you program your plugins with python 3 because with the change from 2019 to 2020 it's planned to get over to python 3 with V 1.4.0 (https://www.youtube.com/watch?v=79mS0get6V8 (3:30))

Thanks Ewald! That is good to know. I am writing my own plugins in Python 3. The issues I currently have is with the existing plugins from the OctoPrint repo. I can't even "octoprint serve" them locally.

Correction. Write plugins so that they support both 2 and 3. OctoPrint 1.4.0 will also support both and there'll be a ton of existing installations out there that will prolly stay running on 2 for a long time to come (at least until OctoPrint drops 2 support)

1 Like

Does it actually contain a plus at the end like that? I think we'd be looking for reasons why the standard python code would fail trying to parse what's returned. (If there's some regex code that tries to look at "2.7.15+" as digits + periods then it might fail.)

Yes there's actually a plus behind the version number...

@foosel might be interested in this... There's a comment in the version.py file's code which suggests that she's seen this before. In theory, it's supposed to see that and to truncate the plus symbol at the end.

def get_python_version_string():
	from platform import python_version
	version_string = python_version()

	# Debian has the python version set to 2.7.15+ which is not PEP440 compliant (bug 914072)
	if version_string.endswith("+"):
		version_string = python_version[:-1]

	return version_string
1 Like

I was able to fix this by editing the line in the get_python_version_string function:

version_string = python_version[:-1]

and updating to

version_string = version_string[:-1]
1 Like

Can you open an issue on the OctoPrint repository, fill out the full ticket for a bug and indicate what you saw and did to fix it?

Thanks