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

NoneType' object has no attribute 'replace #795

Closed
meng25meng opened this issue Feb 29, 2024 · 8 comments
Closed

NoneType' object has no attribute 'replace #795

meng25meng opened this issue Feb 29, 2024 · 8 comments
Assignees
Labels
awaiting info Needs more information from the issuer to continue

Comments

@meng25meng
Copy link

meng25meng commented Feb 29, 2024

Hello, your tutorial, the last error when running to the last step is as follows:

AttributeError                            Traceback (most recent call last)
Cell In[39], line 1
----> 1 scenario.solve()

File D:\Anaconda3\envs\message_env\Lib\site-packages\message_ix\core.py:675, in Scenario.solve(self, model, solve_options, **kwargs)
    656 def solve(self, model="MESSAGE", solve_options={}, **kwargs):
    657     """Solve MESSAGE or MESSAGE-MACRO for the Scenario.
    658 
    659     By default, :meth:`ixmp.Scenario.solve` is called with 'MESSAGE' as the
   (...)
    673         :class:`.MESSAGE_MACRO` class and :class:`.GAMSModel`.
    674     """
--> 675     super().solve(model=model, solve_options=solve_options, **kwargs)

File D:\Anaconda3\envs\message_env\Lib\site-packages\ixmp\core\scenario.py:878, in Scenario.solve(self, model, callback, cb_kwargs, **model_options)
    876 # Iterate until convergence
    877 while True:
--> 878     model_obj.run(self)
    880     # Store an iteration number to help the callback
    881     if not hasattr(self, "iteration"):

File D:\Anaconda3\envs\message_env\Lib\site-packages\message_ix\models.py:219, in GAMSModel.run(self, scenario)
    216 lines2 = ("{} = {}".format(*kv) for kv in self.cplex_opts.items())
    217 optfile2.write_text("\n".join(lines2))
--> 219 result = super().run(scenario)
    221 # In previous versions, the `cplex.opt` file(s) were removed at this point
    222 # in the workflow. This has been removed due to issues when running
    223 # scenarios asynchronously.
    225 return result

File D:\Anaconda3\envs\message_env\Lib\site-packages\ixmp\model\gams.py:305, in GAMSModel.run(self, scenario)
    302 self.scenario = scenario
    304 # Record versions of packages listed in `record_version_packages`
--> 305 self.record_versions()
    307 # Format or retrieve the model file option
    308 model_file = Path(self.format_option("model_file"))

File D:\Anaconda3\envs\message_env\Lib\site-packages\ixmp\model\gams.py:266, in GAMSModel.record_versions(self)
    263 for package in self.record_version_packages:
    264     try:
    265         # Retrieve the version; replace characters not supported by GAMS
--> 266         package_version = version(package).replace(".", "-")
    267     except PackageNotFoundError:
    268         package_version = "(not installed)"  # Not installed

AttributeError: 'NoneType' object has no attribute 'replace'
@glatterf42
Copy link
Member

Hi @meng25meng, thanks for reporting this issue!
Could you please run message-ix show-versions in your message_env virtual environment and share the output here? Because it looks like the code cannot find a package it needs on your system.
Also, please specify which tutorial you are trying to run and whether you made any changes to it.

@glatterf42 glatterf42 added the awaiting info Needs more information from the issuer to continue label Feb 29, 2024
@glatterf42
Copy link
Member

From a quick search online, it doesn't look like version(package) should ever be None. There were bugs in the past where deleting e.g. /path/to/site-package/message_ix-3.8.0.dist-info/* would cause this, but I don't suspect you've done that?

@meng25meng
Copy link
Author

meng25meng commented Feb 29, 2024

Hi @meng25meng, thanks for reporting this issue! Could you please run message-ix show-versions in your message_env virtual environment and share the output here? Because it looks like the code cannot find a package it needs on your system. Also, please specify which tutorial you are trying to run and whether you made any changes to it.

thankyou,asfollows:

(message_env) PS C:\Users\Administrator> message-ix show-versions
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "D:\Anaconda3\envs\message_env\Scripts\message-ix.exe\__main__.py", line 7, in <module>
  File "D:\Anaconda3\envs\message_env\Lib\site-packages\click\core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Anaconda3\envs\message_env\Lib\site-packages\click\core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "D:\Anaconda3\envs\message_env\Lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Anaconda3\envs\message_env\Lib\site-packages\click\core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Anaconda3\envs\message_env\Lib\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Anaconda3\envs\message_env\Lib\site-packages\ixmp\cli.py", line 111, in show_versions_cmd
    ixmp.show_versions()
  File "D:\Anaconda3\envs\message_env\Lib\site-packages\ixmp\util\__init__.py", line 627, in show_versions
    info.append((module_name, version + gl))
                              ~~~~~~~~^~~~
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

@meng25meng
Copy link
Author

From a quick search online, it doesn't look like version(package) should ever be None. There were bugs in the past where deleting e.g. /path/to/site-package/message_ix-3.8.0.dist-info/* would cause this, but I don't suspect you've done that?

我的虚拟环境里确实有您提到的这个版本,不知道是不是这个原因,刚开始安装有点不太熟悉。在虚拟环境里的如下:
6F47E6C6770609048CE7F9FAFC9247D3
Uploading QQ图片20240229220943.png…

@guofei2016
Copy link

Just translate the Chinese from @meng25meng here:
"I do have the version you mentioned in my virtual environment. I don’t know if this is the reason. I was a little unfamiliar with the installation at first. In the virtual environment, it is as follows:"

@glatterf42
Copy link
Member

Okay, so message-ix show-versions should be working inside your environment. From your screenshot, I think the error might originate from the message_ix-0.0.0.dist-info folder being present. For comparison, the only two folder with respect to ixmp and message_ix in my site-packages are:

ixmp-3.8.1.dev9+g9b93531.dist-info
message_ix-3.8.1.dev4+g4dae41e.dist-info

You don't have to worry about the .1.dev... part, this just comes from my specific mode of installation. I'm wondering: what happens if you manually deleted the message_ix-0.0.0.dist-info folder and the same for ixmp, if it exists?
I don't quite know how they got there, maybe something went wrong during installation, but they shouldn't be here either way.

@meng25meng
Copy link
Author

感谢您的建议,我把message_ix-0.0.0.的相关包删除了,现在可以正常运行,非常感谢!

Okay, so message-ix show-versions should be working inside your environment. From your screenshot, I think the error might originate from the message_ix-0.0.0.dist-info folder being present. For comparison, the only two folder with respect to ixmp and message_ix in my site-packages are:

ixmp-3.8.1.dev9+g9b93531.dist-info
message_ix-3.8.1.dev4+g4dae41e.dist-info

You don't have to worry about the .1.dev... part, this just comes from my specific mode of installation. I'm wondering: what happens if you manually deleted the message_ix-0.0.0.dist-info folder and the same for ixmp, if it exists? I don't quite know how they got there, maybe something went wrong during installation, but they shouldn't be here either way.

Thanks for your advice, I have deleted the related package of message_ix-0.0.0. now it can run normally, thank you very much!

@glatterf42
Copy link
Member

Glad this solved the problem :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting info Needs more information from the issuer to continue
Projects
None yet
Development

No branches or pull requests

3 participants