TianZerL / pyanime4k

An easy way to use anime4k in python
MIT License
116 stars 17 forks source link

Cannot Install on Google Colab #2

Open soulspark666 opened 4 years ago

soulspark666 commented 4 years ago

I was trying to install this on google colab notebook, but it shows the following error:

Collecting pyanime4k
  Cache entry deserialization failed, entry ignored
  Could not find a version that satisfies the requirement pyanime4k (from versions: )
No matching distribution found for pyanime4k

The command I used to install it was:

python3.8 -m pip install pyanime4k

pip version used (python3.8 -m pip --version)

pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.8)

Python version used:

Python 3.8.3

I used the above commands since colab has python(3.6) and pip(pip 19.3.1) already installed. I used the following guide to install python3.8 and associated pip.

TianZerL commented 4 years ago

pyanime4k only provides the pre-build binary for Windows x64.

TianZerL commented 4 years ago

It is difficult to provide a general dynamic link library for Linux, if you want to use anime4k in Linux, please consider anime4kcpp directly.

soulspark666 commented 4 years ago

ok since it cannot be used on Linux, I will now close this issue

soulspark666 commented 4 years ago

Hey, could you add it as an enhancement, to get it working on Linux!

TianZerL commented 4 years ago

pyanime4k now supports Linux by manually installing, the newest version are not upload to pypi yet.

TianZerL commented 4 years ago

After countless attempts, I finally launched a Linux version(For most Linux, oldest tested in Ubuntu14.04) that can be installed directly through pip, you can try it. (If you want to run it in a server without graphical interface, you may need install libgtk2.0 first)

sudo apt install libgtk2.0
pip3 install pyanime4k
jcklpe commented 4 years ago

@TianZerL  Thank you! this is awesome!

jcklpe commented 4 years ago

@TianZerL actually I'm having a bit of trouble. I install it from pip no problem but when I try to import it to script it crashes the runtime.

Here's what the google colab logs say:

Jul 8, 2020, 11:40:56 PMWARNINGWARNING:root:kernel 6bd64ed4-2e6b-48c5-a170-5b080196016d restarted
Jul 8, 2020, 11:40:56 PMINFOKernelRestarter: restarting kernel (1/5), keep random ports
Jul 8, 2020, 11:40:56 PMWARNINGsrc/tcmalloc.cc:283] Attempt to free invalid pointer 0x7f26e9304ba0 
Jul 8, 2020, 11:37:47 PMWARNINGWARNING:root:kernel 6bd64ed4-2e6b-48c5-a170-5b080196016d restarted
Jul 8, 2020, 11:37:47 PMINFOKernelRestarter: restarting kernel (1/5), keep random ports
Jul 8, 2020, 11:37:46 PMWARNINGsrc/tcmalloc.cc:283] Attempt to free invalid pointer 0x7fe2a1a9aba0 
Jul 8, 2020, 11:36:55 PMINFOUploading file to /content/basq1.jpg
Jul 8, 2020, 11:32:53 PMWARNINGWARNING:root:kernel 6bd64ed4-2e6b-48c5-a170-5b080196016d restarted
Jul 8, 2020, 11:32:53 PMINFOKernelRestarter: restarting kernel (1/5), keep random ports
Jul 8, 2020, 11:32:50 PMWARNINGsrc/tcmalloc.cc:283] Attempt to free invalid pointer 0x7f3a752c4ba0 
TianZerL commented 4 years ago

@jcklpe

Attempt to free invalid pointer 0x7f26e9304ba0

It works normally on local Linux environment. I guess there is something different about memory management of jupty notebook environment, which caused this.

You can try to run it by python3 src.py instead of jupty notebook.

TianZerL commented 4 years ago

@jcklpe I just tried it on google colab, as I suspected, run it by python3 src.py was all normal, but crashed by jupty notebook.
It should be caused by a memory management policy of jupty notebook.

jcklpe commented 4 years ago

I'm a little new to python stuff. The src.py file would be in whatever package location pip installs to right?

jcklpe commented 4 years ago

@TianZerL Just checked the pip install location on colab, and I don't see a src.py file, nor do I see one in the git repo. Sorry, like I said, I'm new to python and maybe I'm missing something really obvious. I can successfully run !python3 /usr/local/lib/python3.6/dist-packages/pyanime4k/__init__.py but I don't know how to import to the project so that I can just use the pyanime4k functions as part of my larger script.

UPDATE:
I checked in with a friend who knows python stuff and we tried trouble shooting some things. 

Tried to import from the init file like this:

os.chdir("/content/pyanime4k")
from __init__ import *

and no errors returned but when tried to run either pyanime4k.upscale_images("/content/basq1.jpg") or upscale_images("/content/basq1.jpg") just got namespace errors. IE: NameError: name 'pyanime4k' is not defined

in case the import wasn't cascading to the things it was also trying to import we tried using the contents of init by using this:

os.chdir("/content/pyanime4k")
import pyanime4k.error
import pyanime4k.ac
from pyanime4k.upscale import upscale_images, upscale_videos, show_upscaled_image
from pyanime4k.utils import *

and got this:

---------------------------------------------------------------------------

ModuleNotFoundError                       Traceback (most recent call last)

<ipython-input-29-830d03d5cb0c> in <module>()
      1 os.chdir("/content/pyanime4k")
----> 2 import pyanime4k.error
      3 import pyanime4k.ac
      4 from pyanime4k.upscale import upscale_images, upscale_videos, show_upscaled_image
      5 from pyanime4k.utils import *

ModuleNotFoundError: No module named 'pyanime4k.error'

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.

tried running setup from the command line using:

os.chdir("/content/pyanime4k")
!python setup.py install

and got

Traceback (most recent call last):
  File "setup.py", line 11, in <module>
    from pyanime4k.ac import Version
  File "/content/pyanime4k/pyanime4k/__init__.py", line 9, in <module>
    import pyanime4k.error
  File "/content/pyanime4k/pyanime4k/error.py", line 9, in <module>
    from pyanime4k.wrapper import *
  File "/content/pyanime4k/pyanime4k/wrapper/__init__.py", line 9, in <module>
    from pyanime4k.wrapper.acwrapper import *
  File "/content/pyanime4k/pyanime4k/wrapper/acwrapper.py", line 22, in <module>
    os.path.join(curr_path, ac_lib[platform.system()]))
  File "/usr/lib/python3.6/ctypes/__init__.py", line 426, in LoadLibrary
    return self._dlltype(name)
  File "/usr/lib/python3.6/ctypes/__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: /content/pyanime4k/pyanime4k/wrapper/libac.so: cannot open shared object file: No such file or directory

I'm going to look at trying to install and building anime4kCCP but let me know if there's anything you can advise on getting pyanime4k running. If nothing else it's a good learning opportunity for me to understand python better.

TianZerL commented 4 years ago

@jcklpe src.py means a script that you wrote, it could be any name you like.
what I mean is do not use jupty notebook to run a python code but use python3.
for example: you have code

from pyanime4k import ac 

p = ac.AC()
p.list_GPUs()

If you run it by jupty notebook directly, it will crash. So, save it to a file named test.py or any other name you like and upload it to your google colab, then run code:

!python3 test.py

you will see the GPU information.

jcklpe commented 4 years ago

@TianZerL Ooooh thanks. gotcha. 

Yes I can confirm that works. Got to make a weird work around to have it work with the colab project but so far looking good! Thanks!

jcklpe commented 4 years ago

@TianZerL 

Apologies for bothering again, but perhaps you might know what the issue is here:

I need to run pyanime4k in conjunction with another neural network. Basically I've made a Google Colab to run neural-style transfer in batch from folder in a Google Drive. Because of the limitations of neural style transfer outputs I need to upres them using pyanime4k. 

This means that I need to be able to access the variables from the neural-style transfer process in the !python script.py 

obviously script.py doesn't have access to variables declared in the notebook environment so I came up with a way to programmatically create a script.py file and then inject the variables from the notebook process and then run that script using !python so that it wouldn't crash

Here's a link to the colab notebook that I'm trying stuff out on.

Here's a basic test:

testVar = '682.jpg'
importStatement = "import pyanime4k, os, pathlib\n"
imageStatement = f"image = [ pathlib.Path('{testVar}') ] \n"
scriptStatement = f"pyanime4k.upscale_images(input_paths= '{testVar}', output_path= pathlib.Path('/content/output'))"

scriptFile= open("script.py", "w")
scriptFile.write(f"{importStatement}{imageStatement}{scriptStatement}")
scriptFile.close()
!python script.py

and I get the following type error:

Traceback (most recent call last):
 File "script.py", line 3, in <module>
   pyanime4k.upscale_images(input_paths= '682.jpg', output_path= pathlib.Path('/content/output'))
 File "/usr/local/lib/python3.6/dist-packages/pyanime4k/upscale.py", line 149, in upscale_images
   (path.stem + output_suffix, path.suffix)
 File "/usr/lib/python3.6/pathlib.py", line 899, in __truediv__
   return self._make_child((key,))
 File "/usr/lib/python3.6/pathlib.py", line 686, in _make_child
   drv, root, parts = self._parse_args(args)
 File "/usr/lib/python3.6/pathlib.py", line 640, in _parse_args
   a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not tuple

If I replace the pathlib.Path('/content/output') with the string '/content/output' I get instead an error AttributeError: 'str' object has no attribute 'exists'  

I've done a bunch of googling and fiddling around with different approaches but I can't seem to crack what the issue is here?

I also looked at git cloning anime4kCCP and then building it on the notebook, but the cmake version needed to be 3.15 instead of 3.12 and then that meant downloading cmake and uploading it to the colab notebook but at that point, the process isn't very script oriented, and I'm trying to keep everything purely script oriented so that I can distribute the resulting co-lab to other artists who are less technically inclined than me.

TianZerL commented 4 years ago

@jcklpe It do have some problems of the high level API, I will fixed it soon. High level API have another one to maintain it, and I didn't test it strictly after updating, please use AC class temporarily. See the examples in readme.

TianZerL commented 4 years ago

@jcklpe I have fixed it, please upgrade pyanime4k by pip.

jcklpe commented 4 years ago

@TianZerL  Thanks! Works like a charm!

TianZerL commented 4 years ago

@jcklpe I've solved the crash problem on Google Colab, you can directly run it by Jupyter instead of by !python3 test.py. please do not use the pip version, use shell script to build it, see here.

jcklpe commented 4 years ago

thank you @TianZerL !