I am trying to add an interpreter (created using virtualenv) to PyDev but I get the following error:
It seems that the Python /Lib folder
(which contains the standard library)
was not found /selected during the
instal process.
This folder (which contains files such
as threading.py and traceback.py) is
required for PyDev to function
properly (and it must contain the
actual source files, not only .pyc
files) ...
Note that if this is a virtualenv
install, the /Lib folder from the base
install needs to be selected (unlike
the site-packages which is
optional)...
The problem is that there is no /lib folder under my default installation... I created the virtualenv with the 'no-site-packages' option... How can I solve? thanks!
I've come across this myself before. When adding an interpreter created using virtualenv in PyDev, when it asks for the folders that need to be added to the SYSTEM pythonpath, I had to select
/usr/lib/python2.7
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/plat-linux2
See the screenshot for what I had to do. Here temp is my virtualenv.
Even though the system Python directory was added, PyDev did not pick up the global site packages, so you still achieve the "no-site-packages" effect. I'm assuming you would have to do something similar on Windows i.e. select all the folder in the "Select Needed" dialog, including the C:\Pythonx.x folder.
EDIT: I just tried it out with PyDev 2.3 on Eclipse Indigo (Arch Linux with virtualenv 1.7), and it seems that plat-linux2 does not need to be selected (not sure about lib-tk, but /usr/lib/python2.7 is definitely required). Thanks fijiaaron for pointing it out.
EDIT 2: Pydev 2.5 (and probably 2.6 too, from the docs) still requires the /Lib folder to function properly, though it now lets you ignore the "Python stdlib not found" dialog and add the interpreter anyway (but mentions that it still needs to be included later).
to skip this message in pydev you can create manual symbolic links to stdlib not linked by virtualenv.
Example:
ln -s /usr/lib/python3.3/threading.py /home/path/to/virtual/myenv/lib/python3.3/threading.py
ln -s /usr/lib/python3.3/traceback.py /home/path/to/virtual/myenv/lib/python3.3/traceback.py
There is a lot of stdlib not linked in virtualenv. Probably you should make as you need manualy.
Look at /usr/lib/python3.3 and compare with /home/path/to/virtual/myenv/lib/python3.3
You can add, per example, /usr/lib/python3.3/concurrent/ in your pydev path.
if you add /usr/lib/python2.7 (or /usr/lib/python3.3) as suggest by Mr. Bhaduri you can explode your virtualenv because your package could look at site-packages directory in /usr/lib/python2.7 and this is exactly what you dont want.
You want isolate your enviroment. You want your package look only in /home/path/to/virtual/myenv/lib/python3.3/site-packages/
Related
I am developing a program inside a Python virtual environment. Running the command
python -m venv .venv
on Windows, puts the python symlink in .venv\Scripts\ while
python3 -m venv .venv
on macOS puts the symlinks on .venv/bin/. I'm using Visual Studio Code for development and there is a .vscode\\settings.json which needs to point towards the executable's symlinks. For example
{
"python.pythonPath": ".venv\\path\\to\\python",
}
How can I force the venv to put the symlinks in identical locations regardless of the platform?
P.S.1. The .venv folder is ignored by git and is included in the .gitignore file, as AFIK it is not a good practice to ship it with the codebase.
P.S.2. To avoid XY-problem, the final goal is to have an identical development environment on different platforms. Whatever the solution, regardless of the package manager, Visual Studio Code should be able to find the executable's symlinks on different platforms.
P.S.3. I need to find a way to change the __VENV_BIN_NAME__ parameter.
P.S.4. From here, one possible solution might be to use "python.pythonPath": "${env:PYTHON_INSTALL_LOC}", instead.
P.S.5. I asked another question here.
Two things. One, you can't have a virtual environment use bin/ on Windows (see the rejected idea).
Two, the Python extension is running an experiment to get rid of python.pythonPath which will solve your conflict. See the May release blog post for details and how to opt in.
Why does it matter where each OS puts the venv python? If you've correctly made sure that .venv is not in the code base but making sure it's in .gitignore than it doesn't matter if someone who loads up your code even need venv. It's good practice and guarantees that whoever has your code on whichever OS their python, with any dependencies your program needs, is going to be used.
If you are using multiple OS to develop than, create a workspace or project .vscode settings file with those specific settings to the python you want to use but also make sure that .vscode directory in your project is in your .gitignore. Then set up separate .vscode settings on different machines for those OS-specific settings.
I have downloaded a python package to install, on my ubuntu machine. The package has already a setup.py file to use, but I want to change the default python installation address to something else, for this package specifically (and not for good). So what I tried is:
First in the terminal, I export that address of the new folder:
export PYTHONPATH=${PYTHONPATH}:${HOME}/Documents/testfolder/lib/python2.7/site-packages
Then I add this exported address as prefix to the installation command:
python setup.py install --prefix=~/Documents/testfolder
The installation goes through. Now to make python always look for this new path as well (next to the default installation path), I export the address in bashrc file:
export PYTHONPATH="${PYTHONPATH}:~/Documents/testfolder/lib/python2.7/site-packages"
But now whenever I open a terminal and try to import the installed package, it cannot see ("no module named..."). Only when I open a terminal in the folder where I had the installation files (namely setup.py), and run python, can it then see the package, and it works there.
Why isn't my export in bashrc making the package available from anywhere?
Is there something I have done wrong in the above?
To answer your question about the export path. Do you have $PYTHONPATH as a part of your $PATH? If not you should add it to path.
The best way to handle this scenario in my opinion is to use a virtual python environment. There are a couple to choose from, but I like virtualenv the best. The reason to take this approach is because you can manage different versions of python in separate folders. And have separate packages installed in these folders. I recommend looking into it as it is a very useful tool. If you want an examole of how to use it i can provide that https://virtualenv.pypa.io/en/stable/
I have some packages installed under my ~/.local/lib/python2.7/site-packages/ subdir, which was for use with system python (/usr/bin/python). Now I have just installed Anaconda python (which is also python 2.7, but minor version 11). The whole idea of Anaconda distro is to have a self-containing python environment, such that EVERY module resides within anaconda install tree.
But what annoys me is that for some reason I cannot disable inclusion of ~/.local/lib/python2.7/site-packages/ from sys.path although I did not have PYTHONPATH environment variable. Is it possible to run python executable (in this case, Anaconda's python executable) without having to implicitly add ~/.local/lib/python2.7/site-packages/ and the eggs underneath it in the python search path?
Why this problem? Unfortunately the ~/.local/lib/python2.7/site-packages/easy-install.pth also contains a reference to /usr/lib/python2.7/dist-packages, which causes this system-wide dist-packages to still be searched for.
Well, there is a -s flag in python executable to disable searching the user site directory (`~/.local/lib/python2.7/site-packages etc). That solves the problem above!
I'm getting an error while executing a function from a module in PyCharm 5:
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/apple/Dropbox/PycharmProjects/work/2-chapter.py
...
...
AttributeError: 'module' object has no attribute 'corpus'
That is supposed to be nltk.corpus.
After having played with Project Structure (in Preferences) and adding there both /usr/local/lib/python2.7/site-packages and /Library/Python/2.7/site-packages paths, nothing still works out.
I am wondering whether I need to add this path as well /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 ?
The problem is I don't have it. I only have path ...Python.framework/Versions/3.5, although I have already installed python 2.7 as well and the interpreter uses python 2.7.5.
The PYTHONPATH is:
$ echo $PYTHONPATH
:/usr/local/lib/python2.7/site-packages
I also tried adding
import sys
sys.path.append("/usr/local/lib/python2.7/site-packages")
to the module I'm talking about, it also didn't work.
PYTHONPATH is set in "Project Interpreter" section. There you can set your Project Interpreter from any of your locals Python versions or from virtualenv versions.
If you are still experiencing module problems, it could be because that module is not installed
I see a few issues with your current setup:
Project structure pane is for defining your current project's preferences (which folders won't be indexed (excluded), which are to be added to python path (sources)). Based on screenshot, I assume that your project files are in /Users/apple/Dropbox/PycharmProjects/work folder. That is your "content root"
ntlk is a python package. You can check whether it has been installed on Project > Project Interpreter pane. If it is installed and you're using right interpreter for your project, it will be already in pythonpath, hence no additional actions required. Otherwise you should either press the plus button and install it via PyCharm, or use sudo pip install nltk
I have been programming in Python for a while now, and have created some utilities that I use a lot. Whenever I start a new project, I start writing, and as I need these utilities I copy them from where ever I think the latest version of the particular utility is. I have enough projects now that I am losing track of where the latest version is. And, I will upgrade one of these scripts to fix a problem in a specific situation, and then wish it had propagated back to all of the other projects that use that script.
I am thinking the best way to solve this problem is to create a directory in the site-packages directory, and put all of my utility modules in there. And then add this directory to the sys.path directory list.
Is this the best way to solve this problem?
How do modify my installation of Python so that this directory is always added to sys.path, and I don't have to explicitly modify sys.path at the beginning of each module that needs to use these utilities?
I'm using Python 2.5 on Windows XP, and Wing IDE.
The site-packages directory within the Python lib directory should always be added to sys.path, so you shouldn't need to modify anything to take care of that. That's actually just what I'd recommend, that you make yourself a Python package within that directory and put your code in there.
Actually, something you might consider is packaging up your utilities using distutils. All that entails is basically creating a setup.py file in the root of the folder tree where you keep your utility code. The distutils documentation that I just linked to describes what should go in setup.py. Then, from within that directory, run
python setup.py install
to install your utility code into the system site-packages directory, creating the necessary folder structure automatically. Or you can use
python setup.py install --user
to install it into a site-packages folder in your own user account.
Add your directory to the PYTHONPATH environment variable. For windows, see these directions.
If it's not in site-packages then you can add a file with the extension .pth to your site-packages directory.
The file should have one path per line, that you want included in sys.path