run "altinstall"ed python2.4 for nodejs install - python

i'm new to linux, please bear with me.
i'm trying to get nodejs running on my server, but because the default python version is 2.3, and nodejs requires at least 2.4 to install, i have done a "altinstall" of python2.4.
the python should be installed correctly, i can run it like this /usr/local/bin/python2.4, and when i do a version check -V, it shows Python 2.4.
okay so now i'm trying to continue with the nodejs installation, at the ./configure step. the problem is i'm not sure how to actually get the script to use the altinstall-ed python2.4 binary.
i've tried
./configure --prefix=$HOME/local/node -with-python=/usr/local/bin/python2.4
./configure --with-python=/usr/local/bin/python2.4
but they don't work. i still keep getting this error
NameError: name 'set' is not defined
how do i force the script to use this "altinstall"ed python2.4?

I had a look at the sources, and a ./configure --help in the node sources said nothing about specifying your python, so you could try these slightly hackier tricks:
An alias python=/usr/local/bin/python2.4 before you execute configure could work.
It that doesn't work, a symlink in a custom ~/bin directory (or similarly named if it already exists) to the desired Python:
Try creating a bin/ directory in your $HOME path:
~$ mkdir bin # <- in your home path
Then link the Python 2.4 executable into this directory:
~$ cd bin
~/bin$ ln -s /usr/local/bin/python2.4 python
Then at the node source tree, run configure with you ~/bin directory as the first directory in your $PATH:
[your node.js source path]$ PATH=$HOME/bin:$PATH ./configure

Related

VS Code can't find python 3 interpreter

I am installing Python 3.7.2 for the first time, and I'm using the VS Code python extension.
When I run python -V I get Python 2.7.10 which is not correct!
When I select the usr/local/bin/python3 interpreter in VS Code I get this error when running a script:
bash: /Users/erik/Work/Python/usr/local/bin/python3: No such file or directory
But when I look in usr/local/bin I can see that Python3 is there. I'm not sure why VS Code pastes the work directory in front of usr/local/bin ?
My first thought was that Python3 should be in the PATH variable so I ran the included Update Shell Profile command, which gives this feedback:
This script will update your shell profile when
the 'bin' directory of python is not early enough
of the PATH of your shell.
All right, you're a python lover already
Now, after rebooting VS Code I get a new option for selecting an interpreter:
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
Is that different from the Python in usr/local/bin ? When I select it, I get this error:
The script isort is installed in '/Users/erik/Library/Python/3.7/bin' which is not on PATH.
I also get this sideways related error:
You are using pip version 18.1. You should consider upgrading via the 'pip install --upgrade pip' command.
But, when following these instructions I get yet another error:
bash: pip: command not found
All in all, this process and the official documentation seem less than user-friendly? Apparently I'm required to dig deep through my mac's system files in the terminal before even writing one line of code.
Am I missing an essential step here?
I suggest that you use virtual environment for your project
first
pip install virtualenv
open cmd in your project directory that you open in VS-Code (it's important that vs-code sees this virtualenv folder that we will create)
mkvirtualenv my_env
and it will activate it automatically. if not run
my_env/bin/Scripts/activate or my_env/Scripts/activate
Then go open vs-code then select my_env for python interpreter
Well, if you want to change your default Python version for the whole system, it might break some applications that are depending on Python 2.
You can alias the commands by adding this line to your ~/.bash_profile:
$ alias python='python3'
The python command will now refer to python3.
If you want to execute the original Python (which refers to python2), you can escape the alias (so \python will launch python2 without touching the alias).
Btw.
$ unlink /usr/local/bin/python
$ ln -s /usr/local/bin/python3.7 /usr/local/bin/python
could also be a workaround for you.

Make Python 3.6.6 run with python3 and not python

I just installed python 3.6.6 on my server as python 3.7 was giving me too many issues. Unfortunately instead of showing up as python3 executable it is only python. here is the results of dir:
aclocal.m4 config.sub Include Mac Modules Programs Python setup.py
build configure install-sh Makefile Objects pybuilddir.txt python-config Tools
config.guess configure.ac Lib Makefile.pre Parser pyconfig.h python-config.py
config.log Doc libpython3.6m.a Makefile.pre.in PC pyconfig.h.in python-gdb.py
config.status Grammar LICENSE Misc PCbuild python README.rst
I have edited the env path to go to this directory
[root#server]# echo $PATH
/usr/src/Python-3.6.6/python:$PATH
and even
/usr/src/Python-3.6.6/
but obviously that wouldn't work because the python3 command doesn't even exist in the directory. I tried renaming python to python3 so it would run it. Currently the server came with python 2.6.6 and I don't want to disturb that version as I only need this for one piece of software. Though I need to use pip3 and if the system can't find python3 then pip3 command is also not found. Would it have to do with this install process?:
./configure --enable-optimizations --enable-loadable-sqlite-extensions
make altinstall
I wasn't sure if the make altinstall was screwing with it but.
python -3 -m ....
Or
py -3 -m ....
Anything wrong these?
[EDIT]
Further to your comment, it sounds like it could be one of the following:
The file you're trying to use is not in the PATH variable.
https://askubuntu.com/questions/60218/how-to-add-a-directory-to-the-path
Python 3.6 is not in its default position after installation or has been renamed after installation.
Where possible, and practicable, if you're unsure, then ALWAYS install with the relevant installation tool, e.g. apt-get. As far as I'm aware, this will automatically add the directory for Python to the $PATH variable. You can also type that variable into the CLI if you really want to manually check it is 100% in the PATH.

brew install python installs python2

I have 3 versions of python installed on my Mac. 2 of them are through brew i.e. python2 and python3 while the native version is python. the problem is when I put brew install python it installs python2 and not python. (By saying python means the version which runs on putting that command in terminal). What should I do so that if I type python my brew installed python launches.I have my path variables set correctly and the brew installation path is ahead than that of the usr/bin The problem I am encountering is that I have nltk installed through pip, pip2 and pip3 and when I import nltk in python2 and python3 there is no problem but when I do that in python it show no module found.
Try which python in a terminal to see which python will run. Then you know and can act accordingly to fix it.
ls -lsa $(which python) will let you see if it is a symlink to another location or a real executable. if a Symlink you can see where it points to and so you can follow the breadcrumbs to the final binary used.
if you run python from a terminal and in the python REPL do the following
import sys
print sys.path
you can see to which site-packages locations are pointed.
Other than that you of course have the option to use virtual environments to set up your version of python
if you really want python2 to be the default python command you can add a symlink to your ~/bin folder (create it if it does not exist)
mkdir ~/bin
cd ~/bin
ln -s $(which python2) python
chmod +x python
and make sure that export PATH=~/bin:$PATH is added at the back of your .bashrc or .profile or .zshrc file
Now start a new terminal session and try out python again it should point to brews version
Hope that helps

Confusing Python install in user local (virtualenv, pip, distribute)

I tried to install python below way. But this did not work.
This take "error: bad install directory or PYTHONPATH".
What's the proper way to install pip, virtualenv, and distribute for Python?
Make directory
$ mkdir -p ~/.python
Add .bashrc
#Use local python
export PATH=$HOME/.python/bin:$PATH
export PYTHONPATH=$HOME/.python
Create a file ~/.pydistutils.cfg
[install]
prefix=~/.python
Get install script
$ cd ~/src
$ curl -O http://python-distribute.org/distribute_setup.py
Execute and Error
$ python ./distribute_setup.py
Extracting in /tmp/tmpsT2kdA
Now working in /tmp/tmpsT2kdA/distribute-0.6.15
Installing Distribute
Before install bootstrap.
Scanning installed packages
No setuptools distribution foundrunning install
Checking .pth file support in /home/sane/.python/lib/python2.6/site-packages//usr/bin/python -E -c pass
TEST FAILED: /home/sane/.python/lib/python2.6/site-packages/ does NOT support .pth files
error: bad install directory or PYTHONPATH
You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from. The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/home/sane/.python/lib/python2.6/site-packages/
and your PYTHONPATH environment variable currently contains:
'/home/sane/.python'
Here are some of your options for correcting the problem:
* You can choose a different installation directory, i.e., one that is
on PYTHONPATH or supports .pth files
* You can add the installation directory to the PYTHONPATH environment
variable. (It must then also be on PYTHONPATH whenever you run
Python and want to use the package(s) you are installing.)
* You can set up the installation directory to support ".pth" files by
using one of the approaches described here:
http://packages.python.org/distribute/easy_install.html#custom-installation-locations
Please make the appropriate changes for your system and try again.
Something went wrong during the installation.
See the error message above.
My environment('sane' is my unix user name.)
$ python -V
Python 2.6.4
$ which python
/usr/bin/python
$ uname -a
Linux localhost.localdomain 2.6.34.8-68.fc13.x86_64 #1 SMP Thu Feb 17 15:03:58 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
Usually I installed distributed/easy_install aka setuptools in my global Python installation together with virtualenv. From this point on I can created dedicated virtualalized environments using
virtualenv --no-site-packages name-of-environment
Really no idea why to fiddle around with PYTHONPATH here.
Adding /path/to/name-of-environment/bin to $PATH is good enough for adding the virtualized
Python to your $PATH. You don't need any else.
I choice pythonbrew.
I can use multiple Pythons in my home directory by this.
It's a great job.
utahta/pythonbrew - GitHub https://github.com/utahta/pythonbrew

How to build sqlite for Python 2.4?

I would like to use pysqlite interface between Python and sdlite database. I have already Python and SQLite on my computer. But I have troubles with installation of pysqlite. During the installation I get the following error message:
error: command 'gcc' failed with exit status 1
As far as I understood the problems appears because version of my Python is 2.4.3 and SQLite is integrated in Python since 2.5. However, I also found out that it IS possible to build sqlite for Python 2.4 (using some tricks, probably).
Does anybody know how to build sqlite for Python 2.4?
As another option I could try to install higher version of Python. However I do not have root privileges. Does anybody know what will be the easiest way to solve the problem (build SQLite fro Python 2.4, or install newer version of Python)? I have to mention that I would not like to overwrite the old version version of Python.
Thank you in advance.
You can download and install Python to your home directory.
$ cd
$ mkdir opt
$ mkdir downloads
$ cd downloads
$ wget http://www.python.org/ftp/python/2.6.2/Python-2.6.2.tgz
$ tar xvzf Python-2.6.2.tgz
$ cd Python-2.6.2
$ ./configure --prefix=$HOME/opt/ --enable-unicode=ucs4
$ make
$ make install
Then, (if you are using bash) in your .bash_profile do
export PATH=$HOME/opt/bin/:$PATH
export PYTHONPATH=$HOME/opt/lib:$HOME/opt/lib/site-packages:$PYTHONPATH
Then, source the file to make it available
$ cd
$ source .bash_profile
$ python -V
where python -V will return the python version. If the correct version appears, any packages that you run with Python's setup.py util (assuming the developer followed the correct conventions) will install in ~/opt/lib/python2.x/site-packages directory.
Download pysqlite here, cd into the directory you downloaded to, unpack the tarball:
$ tar xzf pysqlite-2.5.5.tar.gz
then just do (if your permissions are set right for this; may need sudo otherwise):
$ cd pysqlite-2.5.5
$ python2.4 setup.py install
one error does appear in the copious output:
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/pysqlite2/test/py25tests.py", line 48
with self.con:
^
SyntaxError: invalid syntax
since as clearly shown that file is for py 2.5 tests only (with statement not present in 2.4!-). Nevertheless the install is successful:
$ python2.4 -c'import pysqlite2'
$
All this is on Mac OS X 10.5 but using python2.4 separately installed from the system-supplied Python 2.5.
The error you report doesn't tell us much -- maybe you're missing the headers or libraries for sqlite itself? Can you show us other output lines around that single error msg...?
If you don't have root privileges, I would recommend installing a more recent version of Python in your home directory and then adding your local version to your PATH. It seems easier to go that direction than to try to make sqlite work with an old version of Python.
You will also be doing yourself a favor by using a recent version of Python, because you'll have access to the numerous recent improvements in the language.
I had the same trouble with gcc failing with Ubuntu Karmic. I fixed this by installing the python-dev package. In my case, I'm working with python2.4, so I installed the python2.4-dev package. The python-dev package should work for python2.6.

Categories

Resources