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

Unable to use unicode strings with Python 2 #76

Closed
flothesof opened this issue Oct 7, 2014 · 10 comments
Closed

Unable to use unicode strings with Python 2 #76

flothesof opened this issue Oct 7, 2014 · 10 comments
Labels
bug Issues that report (apparent) bugs. python-version Compatibility issues, behaviour changes,... between different Python versions. stale For issues lacking activity, whose creators have become unresponsive,...

Comments

@flothesof
Copy link
Contributor

I'm trying to use French labels within a TextClip.
However, the rendering with ImageMagick fails:

UnicodeEncodeError                        Traceback (most recent call last)
<ipython-input-5-9c706287e797> in <module>()
      5                          font=font,
      6                          fontsize=fontsize,
----> 7                          size=(W, H)).set_pos('center').set_duration(5))
      8     if vid != None:
      9         start, end = subsection

C:\Python27\lib\site-packages\moviepy\video\VideoClip.py in __init__(self, txt, size, color, bg_color, fontsize, font, stroke_color, stroke_width, method, kerning, align, interline, tempfilename, temptxt, transparent, remove_temp, print_cmd)
   1048                     os.write(temptxt_fd, bytes(txt,'UTF8'))
   1049                 except TypeError: # oops, fall back to Python2
-> 1050                     os.write(temptxt_fd, txt)
   1051                 os.close(temptxt_fd)
   1052             txt = '@'+temptxt

UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 33: ordinal not in range(128)

There seems to be a possible workaround by doing the following:

#os.write(temptxt_fd, txt)
os.write(temptxt_fd, txt.encode('utf-8'))

But this won't get me any UTF-8 text on the picture. Instead, I get the classical encoding mismatched characters.

Any idea on how to fix this?

Thanks!

@Zulko
Copy link
Owner

Zulko commented Oct 7, 2014

When I use the IPython notebook, any text like "Être à côté" will work. When I use a .py file, I generally need to declare the encoding at the beginning of the file, like this:

# -*- coding: latin-1 -*-

Have you tried that ?

@flothesof
Copy link
Contributor Author

I'm using the IPython notebook with Python 2 and I get the error I posted above. Are you using Python 3 with the IPython notebook?

@Zulko
Copy link
Owner

Zulko commented Oct 7, 2014

I use IPython 2.0.0 which runs with Python 2.7.3 on my computer. Strange.

@flothesof
Copy link
Contributor Author

I don’t know :)

On 18 Nov 2014, at 19:06, oz26 notifications@github.com wrote:

well :)


Reply to this email directly or view it on GitHub.

@Zulko
Copy link
Owner

Zulko commented Nov 21, 2014

I'm not sure I understand what's going on. @oz26 do you have the same bug ?

@adamserafini
Copy link

@flothesof The font matters: if the font doesn't support those characters you'll see question marks. See this thread and this one on the ImageMagick forum for more details.

@flothesof
Copy link
Contributor Author

Hey thanks for writing this here. This might be it. I'm going to try this again and post the result here.

@keikoro
Copy link
Collaborator

keikoro commented Feb 17, 2017

@flothesof Did you ever get around to testing this with a different font? Was what @adamserafini suggested the solution to your problem?

If so, we could add a hint about that to the documentation.

@keikoro keikoro added the bug Issues that report (apparent) bugs. label Feb 18, 2017
@keikoro
Copy link
Collaborator

keikoro commented Nov 25, 2017

Ping @flothesof

@keikoro keikoro added the stale For issues lacking activity, whose creators have become unresponsive,... label Nov 25, 2017
@flothesof
Copy link
Contributor Author

Hi everyone,

Thanks for helping me out on this.
I think I managed to get it working at the time.
I believe the issue can be closed, since the last time I tried this (which was with Python 3) it was working.

I'll close the issue now.

Best
Florian

@keikoro keikoro added python-version Compatibility issues, behaviour changes,... between different Python versions. and removed python2 labels Oct 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that report (apparent) bugs. python-version Compatibility issues, behaviour changes,... between different Python versions. stale For issues lacking activity, whose creators have become unresponsive,...
Projects
None yet
Development

No branches or pull requests

4 participants