Aptana Python stdlib issue with virtualenv - python-2.7

I recently started working on a project using just vim as my text editor with a virtualenv setup. I installed a few API's on this virtualenv from GitHub. Eventually, the project got a little bigger than vim could handle so I had to move the project to an IDE.
I chose Aptana Studio 3. When I started up Aptana, I pointed the project directory to the virtualenv folder that I had created to house my project. I then pointed the interpreter at the Python executable in App/bin (created from virtualenv)/python2.7. When I started reworking the code to make sure I had everything mapped correctly, I was able to import the API's that I had installed just fine. CherryPy came through with no problems, but I've been having an issue with importing a module that I believe is part of the stdlib--urlparse. At first, I thought it was that my python interpreter was 2.7.1 rather than 2.7.5 (I found the documentation in the 2.7.5 section with no option to review 2.7.1), but my terminal is using 2.7.1 and is able to import the module without any errors (I'm using OSX, Mountain Lion). I am also able to import the module when I activate the virtualenv and run my python interpreter. But when I plug "from urlparse import parse_qsl" into Aptana, I'm getting an error: "Unresolved_import: parse_qsl".
Should I have pointed this at a different interpreter and, if so, will I need to reinstall the API modules I had been working with in the new interpreter?

Update: I finally ended up restarting the project. It turns out that not all of the standard Python tools are selected when you select the virtualenv interpreter. After I selected all of the python tools from the list (just after choosing the interpreter), I was able to get access to the entire standard library.
Do NOT just import the modules into your project. Many of the stdlib modules are interdependent and the import function will only import a module into your main project directory, not a libary!

Related

Flask file does not work after deactivation and reactivated. "Flask can't be found"? [duplicate]

I just installed the new python3 module using terminal of Visual Studio Code on ubuntu.
When I import it, this error occurred.
[Python (analysis)] Unable to resolve 'new module'. IntelliSense may be missing for this module.
But the new module surely installed successfully. (I can import it in my ubuntu terminal)
How can I import that new python module in VS code?
You should look up the official docs on it. They have a neat tutorial to get you started.
Here are a few excerpts that should help you:
An "environment" in Python is the context in which a Python program runs. An environment consists of an interpreter and any number of installed packages. Because many programs are written specifically for a certain Python interpreter and makes use of a set of libraries, developers often create and manage an environment for individual programs.
When working with Python in VS Code, you select from available environments using the Python: Select Interpreter command. The Python extension then uses that selected environment for IntelliSense, auto-completions, linting, formatting, and any other language-related features. (The environment is not, however, used for debugging; see Choose a debugging environment.)
The selected environment is also automatically activated when using the Python: Run Python File in Terminal and Python: Create Terminal commands. Installing (or uninstalling) a package in the Terminal with a command like pip install matplotlib installs (or uninstalls) the package in whatever environment is active in that Terminal.
Note: By default, the Python extension looks for and uses on the first Python interpreter it finds in the system path. If it doesn't find an interpreter, it issues a warning. On macOS, the extension also issues a warning if you're using the OS-installed Python interpreter, because you typically want to use an interpreter you install directly. In either case, you can disable these warnings by setting python.disableInstallationCheck to true in your user settings.

pyinstaller single exe of program which uses google api client lib

I have a python program which I've successfully packaged up as a single exe using pyinstaller in the past. Recently I added new features which make use of the google api python client ( https://developers.google.com/api-client-library/python/ ). I've attempted to make a new single exe package of the new version and it fails to run.
I enable debugging and the console and initially the issue was that it hadn't picked up the oauth lib. I fixed that by adding the following to my spec file:
hiddenimports=['googleapiclient', 'apiclient']
When I build I can see this:
53092 INFO: Hidden import 'googleapiclient' has been found otherwise
53093 INFO: Hidden import 'apiclient' has been found otherwise
However, now when I run the rebuilt exe I get the following error before it exits:
pkg_resources.DistributionNotFound: google-api-python-client
I can't see any reference to that and I'm not sure how to force it to be packaged up with the exe.
I figure I can't be the only person to have ever wanted to package up a python program that makes use of the google api, but I failed to find any help during a lot of time with my friend google...
Any tips?
Many People Have same question but I can't find any answer
Try This way
find site package of your project
enter the Pyinstaller/hooks and find hokk-google.api_core.py
add line ( edit line ) datas += copy_metadata('google-api-python-client')
example
from PyInstaller.utils.hooks import copy_metadata
datas = copy_metadata('google-api-core')
datas += copy_metadata('google-api-python-client')
excute pyinstaller hidden-import google-api-python-client
pyinstaller --hidden-import google-api-python-client
you can avoid error
pkg_resources.DistributionNotFound: google-api-python-client
I was able to dig deeper into this issue after I switched from using pip to easy_install to install the google-api-python-client package. Manually installing the egg file gave me a much neater way of testing.
I then started building using pyinstaller with out the --onefile option, this way I was able to start messing with the egg file that was packaged up with my program. Eventually I found out that my problem was stemming from the fact I'm making use of Pandas and the Google API.
Here's the relevant Pandas bug on github.
To solve the problem I had to update my version of Pandas.
I did find that if I moved to the most recent version of Pandas (1.6.0) I ran into a new issue because it imports dateutil and it causes problems looking for the zoneinfo file. I've landed on Pandas 1.5.1 and it is all working.
You can also add site-packages using:
--add-data "path_to_your_package:package_name(e.g googleapiclient)"

import pygtk works but not import gtk

I am configuring pygtk in my centos 5.4 machine. But I am facing few issues.
I want pygtk to be configured to Python 2.7(The default python version is Python 2.4 in centos 5)
So I installed Python 2.7 with different --prefix to my local space and then installed pygobject2.28 and then pygtk2.24 with the --prefix="where python 2.7 installed".
But when I run python2.7 interpreter I am able to import pygtk but, when I try to import gtk it says "no module named gtk."
I have configured PYTHONPATH and PYTHON environment variables to python2.7/lib/site-packages and python2.7 respectively.
My questions:
if pygtk is a wrapper for gtk then why am not able to import gtk, when I am able to import pygtk.
Where does python(or pygtk) pick the gtk from?
And how can I solve the above problem!?
I tried google and other stack overflow questions. But none of them answered the above quesions.
I wasn't checking the ./configure output properly. The problem was, I was trying to install gtk and pygtk without installing cairo and pango. So pygtk skipped building gtk packages because it did not find any cairo package. This was mentioned in the ./ configure script but I had not checked that.
Summarizing:
To configure pygtk to python need to folow these steps
install sqlite-devel #If sqlite needed
install python(2.7)
install gtk(2.24.0) -> requires glib(2.27.3), atk(1.29.2), cairo(1.8.10), pango(1.22.4), gdk-pixbuf(2.21.3)
install pygtk(2.24.0) -> requires pygobject-2.28.3, pycairo(1.8.10)
All the above packages must be compiled to the same prefix, and need to set the PYTHON and PATHONPATH environment variables. The versions of packages also play major role. Added version in parenthesis that worked for me.
There are many dependencies while installing some of the packages so I had to install following packages using yum: libxext, librender, gettext, zlib, libgtk2-devel

Install Numpy compiled for VS2010 for an embedded interpreter

Another of my queries about an embedded Python 2.7.3 interpreter on Windows. I need to install numpy and matplotlib as support packages for an embedded interpreter in a C++ program compiled in Visual Studio 2010.
Some background:
I've been trying to make this work for a few months. The main issue is that numpy for Python 2.7 is compiled against an earlier version of the MS C library (VS2008) whereas my application is compiled against the 2010 version (a fact beyond my control - that is the office compiler).
I worked around this by fiddling with the manifest for my application to let it load the correct C library for numpy and this got it to import. As an end-user has tried out new features, bugs have started to appear, including untraceable crashes.
My current state:
I pinned some of these down to a poor compilation on my part of the Python 2.7.3 source, in particular the dependencies (lots of the crashes seemed associated with Tkinter from matplotlib). So I started afresh on the Python compilation and now have a clean compiled version of all the core and dependencies of Python 2.7.3. Now I'm looking at numpy/matplotlib.
My questions
Is it worth attempting to compile numpy against VS2010 or is my earlier manifest mangling solution the only way?
If the former, what problems might I encounter in doing so (i.e. what should I watch ou for)?
In the latter, how do I get numpy to install in the lib/site-packages folder of my embedded intepreter?
use cygwin to build numpy on windows.
I am on windows-xp
Its working fine for me.. .!
In cygwin python2.6 comes as a default python. I have installed python2.7 but not installed numpy in python2.7.
To use it on python2.7 i have run python2.7 setup.py build
You can see that in screen-shot of my terminal. and in folder 'namit' i have placed 'numpy' dir that i have compiled on cygwin.
when i have imported numpy when i am in that dir.. it worked...you can see that in globals() from where it has imported.

django in virtualenv with pydev

mac ox 8.2, eclipse juno, python 2.7, django 1.4.1, pydev 2.7.1.2012100913
I'm relative new with python/django and I'm trying to get it to work with pydev in a virtualenvironment. I set up the virtualenvironment installed django and successfully created and started a django project. After that I decided that I want to use my favorite editor eclipse.
I created a new pydev/django project, configured and selected a new interpreter (from virtualenv) and used that, I also included the virtualenv/lib/python2.7/site-packages/django in the interpreter libraries. However after going the next dialog, I got an error message "Django not found"
I went over the documentation but I haven't found any solution yet.
I was also wondering whether the workenvironment (or the actual code) needs to live in a subdirectory of the virtualenv directory) And whether the virtualenv must be activated (I suppose so), tried all these options but no luck yet.
As far as I'm aware you don't need the django installation (i.e., virtualenv/lib/python2.7/site-packages/django) in your interpreter libraries. Having the site-packages in there (i.e., virtualenv/lib/python2.7/site-packages) should suffice for your interpreter to find any django.* package.
putting this in your interpreter libraries:
virtualenv/lib/python2.7/site-packages/django
wiil not work, because there is no virtualenv/lib/python2.7/site-packages/django/django (yes, twice), this translates to the following:
export PYTHONPATH=<...virtualenv>/lib/python2.7/site-packages/django:$PYTHONPATH
python -c 'import django'
which fails with ImportError message. you need to give the parent directory.
virtualenv/lib/python2.7/site-packages
which translates to the following:
export PYTHONPATH=<...virtualenv>/lib/python2.7/site-packages:$PYTHONPATH
python -c 'import django'
.