Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using time.perf_counter module #3

Merged

Conversation

marcobassoli
Copy link

Hello, I was trying to install this fantastic add-on on the new blender 2.90 version (for Linux) but, when trying to enable it, I got stuck with this error:

Exception in module register(): /home/marbasso/.config/blender/2.90/scripts/addons/molecular/__init__.py
Traceback (most recent call last):
  File "/usr/share/blender/2.90/scripts/modules/addon_utils.py", line 382, in enable
    mod.register()
  File "/home/marbasso/.config/blender/2.90/scripts/addons/molecular/__init__.py", line 42, in register
    from . import properties, ui, operators
  File "/home/marbasso/.config/blender/2.90/scripts/addons/molecular/operators.py", line 1, in <module>
    from time import clock, sleep, strftime, gmtime, time
ImportError: cannot import name 'clock' from 'time' (unknown location)

As the first try, I downloaded the Blender 2.83.7 LTS version (for Linux), but the error was the same.
Then, I tried to clone this Molecular Script repository and compile myself using the make_release.py file but always received the same error during the add-on enable.
So I tried to investigate a bit more and found a similar error on other Python-based repositories (not related to Blender), in which I found the possible cause.

In fact, according to Python 3.8 documentation:

The function time.clock() has been removed, after having been deprecated since Python 3.3: use time.perf_counter() or time.process_time() instead, depending on your requirements, to have well-defined behavior. (Contributed by Matthias Bussonnier in bpo-36895.)

I verified my Python installation and it is the 3.8.5 version, this may be the source of the problem. I didn't want to downgrade, so I started to modify the code to try to solve the issue. I wanted to modify as few parts as possible to keep the main code untouched, so I just replaced all the lines importing time.clock with lines importing the new time.perf_counter using the old "clock" name.
In other words, I did the following substitution:

from time import clock -> from time import perf_counter as clock

In this way, all the original calls to the clock function actually turn to be a call to the new perf_counter function. After compiling, installing and enabling, the add-on works like a charm!

Is it safe to do a merge in the master branch? Since the clock module has been removed, this problem might be more frequent in the future. However, I don't know what is the impact on older versions of Blender and/or Python.

MarBasso added 2 commits October 6, 2020 12:00
Updated the code to be compliant with Python 3.3+ distributions, in which the time.clock module is deprecated and replaced by time.perf_counter. To minimize the modifications, I imported the perf_counter module and locally named it as clock. With this approach, the rest of the code is untouched.
Updated the code to be compliant with Python 3.3+ distributions, in which the time.clock module is deprecated and replaced by time.perf_counter. To minimize the modifications, I imported the perf_counter module and locally named it as clock. With this approach, the rest of the code is untouched.
@marcobassoli marcobassoli changed the title Using time.perf counter module Using time.perf_counter module Oct 6, 2020
@scorpion81 scorpion81 merged commit 16fb143 into scorpion81:master Oct 9, 2020
@powderblue042
Copy link

Hi!
Sorry if I shouldn't be pitching in here, but I tried to install Molecular 1.1.2 and I got this error message. Any advice or suggestions about how I can make this work in Blender?
Thank you!
Untitled

@CommanderLouiz
Copy link

CommanderLouiz commented Oct 10, 2020

I also got the same error that powderblue did.

@scorpion81
Copy link
Owner

scorpion81 commented Oct 11, 2020

Hi,
sorry for the inconvenience. I built 1.1.2 now against Python 3.7 instead of Python 3.8. Was thinking blender 2.90 already switched to Python 3.8. Could you please try whether the 1.1.2a release works for you ?

Edit: In order to compile this on your own, you need under windows Visual studio 2017 community edition (2019 should work as well) and a version of Python 3.7.x. You need also to install Cython via "pip install cython". Then you just need to invoke "python make_release.py" and a zip according to your OS should be made, after compiling core.pyx.

@powderblue042
Copy link

Hey scorpion81,
Thanks for the response! I'm googling, but I'm not sure I can find 1.1.2a... Also, could repeat the bit about how to install it again? I'm not sure I've even HEARD of some of those things! :P

@scorpion81
Copy link
Owner

Hey scorpion81,
Thanks for the response! I'm googling, but I'm not sure I can find 1.1.2a... Also, could repeat the bit about how to install it again? I'm not sure I've even HEARD of some of those things! :P

Just install the latest release as usual (with the zip file).
https://github.com/scorpion81/Blender-Molecular-Script/releases/latest
I had to re-tag it to 1.1.2a here on github, but inside is just version 1.1.2, with core.pyx built against Python 3.7.
The compilation instructions are totally optional, just in case you wanted to build it from source on your machine :)

@CommanderLouiz
Copy link

Hey scorpion81,
Thanks for the response! I'm googling, but I'm not sure I can find 1.1.2a... Also, could repeat the bit about how to install it again? I'm not sure I've even HEARD of some of those things! :P

Just install the latest release as usual (with the zip file).
https://github.com/scorpion81/Blender-Molecular-Script/releases/latest
I had to re-tag it to 1.1.2a here on github, but inside is just version 1.1.2, with core.pyx built against Python 3.7.
The compilation instructions are totally optional, just in case you wanted to build it from source on your machine :)

I installed your re-compile, and it enables correctly!
Now I just need to figure out how to use it to do what I want...

@powderblue042
Copy link

Hi scorpion81, and Sir CommanderLouiz Sir! :D
You're a wizard, it works like a dream! Follow-up question though, I want my particles to 'burst' out from the center using the velocity from the normal, but if I render with Self Collision the particles self-collide as they begin in the centre and just explode out into the void way too quickly. Is there some way to key the collision or anything like that?
Thanks a bundle :)

@DeepDeeh
Copy link

Hi scorpion81! I tried installing the addon 1.1.2 (both Versions, Python 3.7 and 3.8) on my Ubuntu 20.04. But I cannot activate the addon and got the same error like powderblue042. I asked in this question about it. Maybe you could give me some advise what I should try? https://blender.stackexchange.com/q/208134/114757
molecular-install-error-2021-01-13 21-40-56

@scorpion81
Copy link
Owner

@DeepDeeh

I have rebuilt molecular against Python 3.7 on my local linux machine. It uses blender's bundled statically linked python executable.
You can find that in the release tag 1.1.2b .

If make_release.py (and hence cython) is called from this, the resulting .so module from molecular will not depend on libpython3.7m.so.1.0 any more.

Seems the build setup here in Github actions relies on python using its own shared library instead a static one.

And in case you need to use a different python version for a blender version bundled with a linux distro, you just need to build molecular against that particular python version.

@DeepDeeh
Copy link

@scorpion81
Thank you very much! I just installed, and it works now. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants