VIM installation and Anaconda - vim

I'm using Anaconda and have an environment for Python27 and in the near future, one for Python3.
I ran into trouble with vim using rope, b/c my original build was linked to my /usr/local/vim ( i think..or something close to that).
I realized from reading, that i should re-build vim with:
./configure --enable-pythoninterp --with-python-config-dir=/home/wbg/anaconda/envs/py27/lib/python2.7/config --enable-prefix=/home/wbg
So I'm wondering, if there's a better way to install vim, so that when I change Anaconda environments, my vim will change too.
TIA !

This is an old question, but I find this very useful, so I share it here.
conda forged vim takes care of conda envs and python linking:
conda install -c conda-forge vim
For more information: https://anaconda.org/conda-forge/vim

Vim can be built in four ways:
No Python support (-python, -python3)
Python 2 support only (+python or +python/dyn, -python3)
Python 3 support only (-python, +python3 or +python3/dyn)
Python 2 and 3 support (+python/dyn, +python3/dyn)
I think you should opt for the last option; but, this choice brings some extra headaches. When Python 2 and Python 3 are both supported they must be loaded dynamically. And, you will not be able to use Python 2 or 3 in the same Vim session. You can build with both, but once one version of python is invoked in Vim the other cannot.
On windows, you'll want to enable dynamic loading of the python interpreter. If python is found in the path, it will be useable in vim. This frees you up from worrying where python is installed. For example:
./configure --with-features=huge --enable-pythoninterp=dynamic --enable-python3interp=dynamic
On Debian-based systems, to build both versions of python you'll need to use something like:
./configure --enable-pythoninterp=dynamic --with-python-config-dir=$(shell python-config --configdir) -enable-python3interp=dynamic --with-python3-config-dir=$(shell python3-config --configdir)
(For extra details see: https://askubuntu.com/questions/585237/whats-the-easiest-way-to-get-vim-with-python-3-support).

Related

python versions (conda -forge)

I am using 18.04 Ubuntu with Anaconda.Recently i have trying to install OpenCV through conda-forge channel in the base environment. I did not install purposely any Python version and did not use any pip command either in base environment. Now, in the base environment, if execute just python, i get the same python version as system version and if execute python3 , i get the version installed by conda-forge. Please refer the screen shot. Python_on_Conda_base
I would like to know what is difference between python and python3 command?.What is should i keep in mind? basically i prefer the version 3.7.5 Python
.So, only the Python3 has uses different version. So, question what i should take note when i using python3 some_script.py? what is pros and cons of having this 2 version?
So far,i did not face any issues, but removed the conda-forge channel from Anaconda to avoid any conflicts. Any thoughts?
After posting this question, i have noticed python --version command gives Python 3.7.5 on Conda base environment and Ubuntu terminal (outside Conda)
You most likely have set an alias for python to point to the python3 binary.
Check this by typing type python, which will probably give you
python is aliased to ...
The crux here is that an alias will not be detected by which and as you revealed in the comments your which python returns the correct python version from your conda base environment, which makes an alias the most likely explanation, as PATH issues can be ruled out.
If above command does indeed reveal an alias, then check you .bashrc or similar file that you might have modified for a line alias python=.... Delete it, restart your terminal and everything should work normally

Python version doesn't seem to be updating

Here is what I get when I run the following commands in my terminal:
python --version
python 2.7.1
python3 --version
python 3.7.3
I ran the 'Update Shell Profile.command' file that comes with the Python3 download, but it still doesn't change the value of
python version
when I run it. My question is, is this normal? Does it change anything important other than needing to type 'python3 file.py' to run 'file.py'? If so, how do I change this? (Also, the computer I am using uses Homebrew which I am not familiar with, I am not sure if this changes anything or how.)
Python 2.7 and Python 3.7 are the latest releases of python 2 and 3 repsectively. Those two are two different version which can co-exist together. You can have both versions installed in your computer at the same time. If u dont like that just uninstall one(I'd suggest python2). The main difference is that python 3 offers many advantages compared to python 2. Some of them would be that some libraries work only for that version other legacy ones work for the other version etc. So there is no problem with having both but like i said there is really no point. Just choose whch version u like and uninstall the other one.

Vim could not load libpython3.7m.a with python3 from Anaconda

I'm trying to use Anaconda python3.7 + vim 8.1 + jedi-vim on Rocks 7.0 (Manzanita) but I get an error saying that libpython3.7m.a cannot be loaded and I can't find a solution.
First things first. I have to compile vim by myself because the vim installed by default has only +python and I have to use python3.
I cloned the git and, following several other suggestions found online I configure vim with
./configure --enable-cscope --enable-multibyte --enable-python3interp=dynamic --with-features=huge --with-python-config-dir=/home/mazzi/miniconda3/lib/python3.7/config-3.7m-x86_64-linux-gnu --with-tlib=ncurses --enable-fail-if-missing --prefix=/home/mazzi/.local
The prefix is due to the fact that I don't have root access and its output of can be found here. Please note that during the whole procedure I had to stay inside a conda environment, otherwise the configuration would fail saying that no python3 was found.
I then make, with this output, and make install with this other output.
I check vim version and everything seems ok.
Finally, I start vim normally (/home/mazzi/.local/bin is on the PATH, before the system paths, and the vim command points to ~/.local/bin/vim) and type :py3 pass but I get the following error:
E370: Could not load library libpython3.7m.a
E263: Sorry, this command is disabled, the Python library could not be loaded.
What can I do?
Additional info
Some of my sources:
https://github.com/Valloric/YouCompleteMe/wiki/Building-Vim-from-source (without sudo and just to be clear I did not try YouCompleteMe due to some issues in the past that forced me to go to jedi-vim)
https://gist.github.com/hxhc/778d7c3a3ad491dedf3675a47275a979
Compiling vim 8.0 with Python 3 support resulting in SIGABRT
https://github.com/Valloric/YouCompleteMe/issues/2855#issuecomment-352181535

Pip freeze doesnt show freshly installed packages with Pycharm

I use Pycharm to create and manage my virtualenvs in my projects.
The problem is that after adding a library with pycharm, when I type the command (pip3 freeze --user), the library does not appear in the command result.
I have to manually type the pip install command each time so that the library is visible.
What manipulation should I do in PyCharm to solve this problem?
For what you are saying, the first thing that comes to mind is that you should use:
pip freeze
And not
pip3 freeze
Because the command mapped to the pip version when you have virtualenv activated is the first. Note that for installing you seem to use pip, and not pip3
Moreover, the --user option afaik is related to the packages installed in the user folder:
--user Install to the Python user install directory for your platform. Typically
~/.local/, or %APPDATA%\Python on
Windows. (See the Python documentation for site.USER_BASE for full details.)
If your packages are installed in the virtualenv folder, I would tell you to not use that option.
Also please make sure you have your virtualenv activated. In linux you can do so by source path/to/virtualenv/activate
Edit
I understand that the reason you are using pip3 is because you may have different versions of Python in your machine. Let me explain you a bit further how it works, because version management is usually a headache for many programmers and it is common to find problems when doing so.
If you install different versions of Python in your linux machine, and you do that as root, then the installation will proceed for the whole system. Usually Python2 installation folder for Linux machines is /usr/bin/python. However, I am uncertain of which directory is used for Python3 installations. You can check that easily by doing whereis python3. You can serach the path to binary of any command by doing whereis command. Note that this works also for whereis python as far as you don't have virtualenv activated.
Aditionally, the link to the binary of a command (or the set of instructions to be exectued, more broadly) is defined in certain folders in Linux, depending on whether you created the command as root or as a user, and possibly also on the distro. This works differently in Windows, that uses the Registry Edit utility to handle command mappings. When you enable your virtualenv, what you are doing is creating an environment that enables mapping system commands such as python to the Python installation in your virtualenv folder.
When you disable the virtualenv, the command points again to the default installation path. Same happens with pip, so incorrect usage of this tool may result in different packages being installed in different locations, and therefore not appearing available for the right Python version at any given circumstance.
In Linux, environment variables are shell dependent, though you can write them out with echo $variable and set them with variable=value (from bash). The search path is simply called PATH and you can get yours by typing echo $PATH.
Source: https://askubuntu.com/a/262073/426469
I encourage you to check other questions in SE network such as this: https://unix.stackexchange.com/a/42211/96121, to learn more about this.
Addendum
Quick tip: it is common to use the pip freeze command as follows:
pip freeze > requirements.txt
It is a standard that leads to understanding that modules in such file are required for the correct functioning of your application. That lets you easily exclude the virtualenv folder when you install the program in another computer, since you can readily know the requriments for a fresh installation. However, you can use the command as you want.

Why isn't lib in Python 3 install DOS PATH?

I installed Python 3.4 on a 64-bit Windows 7 machine. Works fine. I did choose the option to have Python added to the DOS PATH environment variable so that I could work at DOS command line, write python .py and it would work without having to type the full Python installation directory.
But when I tried to use pydoc, I discovered that it didn't know where pydoc was. Why? Because only Python34 and Python34\scripts are in the PATH. Why not also Python34/lib which has all sorts of useful tools, including pydoc.py?
If the command isn't bound, for whatever reason, Invoke pydoc with -m, e.g.
python -h
python -m pydoc some_file.py

Resources