I'm trying to run the benchmarks game repo bencher script which was written in python 2 and requires the gtop module, NOT the pygtop module. After searching everywhere and even following their README.md I could not figure out how to get this in my python 2.7.18 virtual environment (created and maintained using pyenv).
I decided to have a look at my system version of python 2.7.18 as I followed the guide from this SO reply and the packages downloaded/installed successfully. My system version of python can import the module just fine:
Python 2.7.18 (default, Mar 8 2021, 13:02:45)
[GCC 9.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gtop
>>> gtop.__file__
'/usr/lib/python2.7/dist-packages/gtk-2.0/gtop.so'
So apparently it comes as a .so which I've researched is like a DLL library for Ubuntu (correct me if I'm wrong)?
Is there a way for me to just copy this into my virtual environment of the same python version?
Thank you to #SamBob for suggesting the SO reply that led to the answer.
What I've been mistakenly doing is copying the gtk-2.0 directory into my virtualenvs site-packages such that:
$HOME/.pyenv/versions/<venv>/lib/python2.7/site-packages/gtk-2.0/gtop.so
What I've done is instead copy just the gtop.so library into the virtualenvs site-packages, and it seemed to recognise it no problem, such that
$HOME/.pyenv/versions/<venv>/lib/python2.7/site-packages/gtop.so
Here is my output now:
Python 2.7.18 (default, Oct 18 2021, 23:18:58)
[GCC 9.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gtop
>>> gtop.__file__
'/home/muffin/.pyenv/versions/project-2.7.18/lib/python2.7/site-packages/gtop.so'
>>>
Related
Here is an extract of my console in a Mac, as you can see the Python on the console is 2.7.15 but on the environment it becomes 2.7.10 which is an older version... any help on why and how to fix it would be most welcomed!
dhcp-18-57:Wakeup6 **jbs$ python**
**Python 2.7.15** (default, May 1 2018, 16:44:14)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
dhcp-18-57:Wakeup6 jbs$ virtualenv env
New python executable in /Users/jbs/PycharmProjects/Wakeup6/env/bin/python
Installing setuptools, pip, wheel...done.
dhcp-18-57:Wakeup6 jbs$ source env/bin/activate
(env) dhcp-18-57:Wakeup6 **jbs$ python**
**Python 2.7.10** (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
If you installed python using Anaconda, then set up a new virtual environment for python 2.7.15 Then following directions in the Anaconda documentation, activate this virtual environment and you should be good to go.
If you didn't use Anaconda, just follow the directions for setting up a virtual environment on a Unix box. Then activate that environment and start working.
You can have multiple versions on your computer. Virtual environments allow you to run the version you want. I have virtual environments for python 2.7.13 and python 3.6.
If this doesn't work please let me know. I'll try to help.
Thank you all for your input. I finally figured out how to solve it. The difficult part was finding out how to locate the place where python 2.7.15 was installed which I'll leave intact in the response since I found it by trial and error looking in other places. I have not found a command that gives you the full path (perhaps an expert can tell us how to go from the laconic which python to the full path).
What I find interesting is that it does not really matter what the console uses when calling virtualenv. What matters is the version of Python used to install virtualenv which is the default version that will be used.
Essentially one has to use the -p option in virtualenv and make sure to find the right location where the desired version of python is.
dhcp-18--41:WakeUp8 jbs$ virtualenv -p /usr/local/Cellar/python#2/2.7.15/bin/python env
Running virtualenv with interpreter /usr/local/Cellar/python#2/2.7.15/bin/python
New python executable in /Users/jbs/PycharmProjects/WakeUp8/env/bin/python2.7
Also creating executable in /Users/jbs/PycharmProjects/WakeUp8/env/bin/python
Installing setuptools, pip, wheel...done.
dhcp-18-189-34-41:WakeUp8 jbs$ python
Python 2.7.15 (default, May 1 2018, 16:44:14)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
dhcp-18--41:WakeUp8 jbs$ pwd
/Users/jbs/PycharmProjects/WakeUp8
dhcp-18-189-34-41:WakeUp8 jbs$ source env/bin/activate
(env) dhcp-18-189-34-41:WakeUp8 jbs$ python
Python 2.7.15 (default, May 1 2018, 16:44:14)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
I successfully installed nltk and works fine. I have to run a file where nltk was imported and tensorflow too ,hence, i have to activate tensorflow.
When I activate tensorflow the .py file i want to run gives an error. I have read some solution but they didn't help.
HP-250-G5-Notebook-PC:~$ python
Python 3.6.3 |Anaconda custom (64-bit)| (default, Oct 13 2017, 12:02:49)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
>>>
this works fine but this does not
(tensorflow)HP-250-G5-Notebook-PC:~/AIG2018/Chatbot$ python
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
What is that I am doing worng?
ImportError: No module named 'nltk'
You're using two different versions of python, and you probably installed nltk in your root environment, but not your virtual environment. When you "activate" the environment called tensorflow, you are using a different virtual environment, in which you haven't installed nltk. Try activating tensorflow, then using pip install nltk, then starting python. Because you seem to be using anaconda, this would probably look like this:
# Do these first 2 steps in your terminal:
source activate tensorflow
# you're now in the virtual environment called tensorflow
pip install nltk
# you now have nltk in that virtual environment
# Now, you can start python
python
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
And you shouldn't have that error
If you look closely at your messages you will see that the successful import of nltk is on Python 3.6.3 and the failed import is on Python 3.5.2.
This indicates that you have two Python installations of different versions, and nltk is installed in one but not in the other.
I have installed cassandra 3.0.0 and trying to connect to connect cqlsh. when i try to hit ./bin/cqlsh from the dir of installed cassandra I am getting
python not found. I am using ubunut14.04LTS
when i type python2 in my terminal it says
python2
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
when i type python3 in my terminal it says
python3
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
so this mean it is already installed . But yes when i type
python in terminal it says
python
The program 'python' is currently not installed. You can install it by typing:
apt-get install python-minimal
even when i install python-minimal it doesn work.
please suggest..
Create a symbolic link /usr/bin/python pointing to either /usr/bin/python2 or /usr/bin/python3
~$ python
bash: python: command not found
while running python2 and python 3 its showing different versions.
~$ python2
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
~$ python3
Python 3.4.0 (default, Jun 19 2015, 14:20:21)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
i think somehow default python link is broken. i can't seem to access ubuntu software center also.
Please suggest a way to fix this.
Rather than re-creating the simlink as suggested, I would start working with virtualenv. You can create virtual environment pointing at different python versions by doing:
virtualenv -p /usr/bin/python2 venv_name (for Python 2.7)
virtualenv -p /usr/bin/python3 venv_name (for Python 3)
Once you go into the venv and do the source venv_name/bin/activate, your python symbolic link will be pointed at the version you've chosen when creating it.
Also, you might find a pyvenv link which will be associated to Python 3 as this version of Python comes with virtualenv (and pip) out of the box. You might need to install virtualenv with pip (or easy install), and to figure it out which Pythonversion is your pip associated to, you can do pip --version
I want to access files and directories which may require root permission from a command line call to a python script using Enthought Canopy Python. However running python as root gives me the system distributed python.
$ python
Enthought Canopy Python 2.7.6 | 64-bit | (default, Sep 15 2014, 17:36:10)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
$ sudo python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Same results using default bash terminal (Ubuntu Linux 14.04) and using the canopy command line (Canopy 1.5.2).
I reinstalled Canopy as root (i.e. re-ran the shell script as root) and the same problem still occurs.
Is there an easy way to run Canopy as root? I am not trying to distribute it to a number of users on a system just run a python script on files that need root permissions.
It sounds like sudo is not using your current PATH settings to locate the executable to run. IIRC this is a configuration option for sudo, whether to use a limited default PATH or not.
An easy way to work around this is to specify the full path to the python excutable that you want to execute. For example, if you've activated a Canopy virtual environment, then you can do it like this:
$ sudo $VIRTUAL_ENV/bin/python