Fix cannot generate tempfile error

Fix #297