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

AttributeError: module 'site' has no attribute 'getsitepackages' when running p4a create #610

Closed
MelvIsntNormal opened this issue Jan 23, 2016 · 13 comments

Comments

@MelvIsntNormal
Copy link

Hopefully this is just me doing something wrong.

I created a test project to test building an APK using Python 3.5. I'm running this comand:

p4a create \
        --dist_name=testproject \
        --bootstrap=sdl2 \
        --requirements=sdl2,python3crystax,kivy \
        --android_api=19 \
        --ndk_dir=/home/melvisntnormal/.android/ndk_crystax/

which gives me the above error. Any way to get this working?

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@inclement
Copy link
Member

This might be because of the current slightly hacking hostpython3 usage (i..e. trying to run python3.5 from the system). Does your python3.5 installation let you run site.getsitepackages()?

@MelvIsntNormal
Copy link
Author

Nope. Attempting to run it in the terminal gives the same error:

(kivy-3.5) melvisntnormal@msowah-e5440 ~/Projects/Android/3_5_test $ python
Python 3.5.1 (default, Dec 18 2015, 00:00:00) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import site
>>> site.getsitepackages()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'site' has no attribute 'getsitepackages'

@inclement
Copy link
Member

Okay, interesting, this is not a scenario I had considered and I'm not sure what property of the installation causes this problem. Is it in a virtualenv?

@MelvIsntNormal
Copy link
Author

Yeah this is a virtualenv. I've installed Kivy, P4A, and its dependencies on it

@inclement
Copy link
Member

I think this is probably caused by this known issue in virtualenv (though I'm not certain). Possible workarounds for now include:

  • install and use python3.5 outside a virtualenv
  • modify python-for-android to use a different method for finding the site packages dir
  • copy a working site.py into the local directory (not sure if this will work)

I appreciate that none of these are ideal, and I'll look at fixing this sooner rather than later (hopefully with an ideal method, using a locally built python), but that's probably the status for now.

@MelvIsntNormal
Copy link
Author

Hmmm. I haven't really had a very comfortable experience with building for android outside a virtualenv to be honest. What is the method used for? Is it just finding a list of the directories of installed packages?

@inclement
Copy link
Member

It's used here to get the site-packages dir so that we can add it to our modified PYTHONPATH when building modules for android.

I appreciate that this isn't ideal, and intend to fix this by building a local hostpython3 as is done with python2. The current state is a convenient workaround to use the local system python instead.

@MelvIsntNormal
Copy link
Author

All right, I guess I'll wait for an actual fix. In the meantime, I've used a probably naive solution and changed "\\n".join(site.getsitepackages()) to os.path.dirname(site.__file__) + "/site-packages", and it works just fine (though the apk crashes on my phone, but so did the python2.7 and Kivy Launcher versions). Is there any reason why using os.path.dirname(site.__file__) + "/site-packages" is a bad idea?

@inclement
Copy link
Member

That seems like an adequate solution for now.

For the crashing on the phone, there's a bug right now that seems to cause compilation for the wrong architecture, but this doesn't affect everyone and I haven't pinned down the reason yet. It might also be something else.

@MelvIsntNormal
Copy link
Author

OK then, I'll use that until an official fix is released. The crashing issue seemed to have something to do with an empty _event.so file. I'll open a separate issue once I get some more information.

@kasaiee
Copy link

kasaiee commented Apr 15, 2017

@MelvIsntNormal Hi, I had exactly this error in django. I solved issue by opening manage.py and add this code to first line of it.
#!/usr/bin/python3.5 python

@AndreMiras
Copy link
Member

@inclement should we use one of the workaround as a fallback method?
Like the one suggested in the upstream ticket pypa/virtualenv#355 (comment)
We can try/catch and do the workaround on AttributeError. If you're interested I can work on the pull request.

@inclement
Copy link
Member

Closing as stale, since it should be resolved by moving away from crystax and having a proper hostpython again for our own use.

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

No branches or pull requests

4 participants