4

I ran the following code

# Allows the use of display() for displaying 
from IPython.display import display DataFrames

It displayed the following error:

 File "/usr/lib64/python2.7/site-packages/IPython/utils/colorable.py", line 13, in <module>
    import pygments
ImportError: No module named pygments

So I tried installing pygments:

pip install pygments

and it says:

Requirement already satisfied: pygments in /home/rico/downloads/hgvs-0.1.2/Pygments-2.1.3-py2.7.egg (2.1.3)

Do you have an idea how to resolve this issue? Thanks.

Arturo Moncada-Torres
  • 1,236
  • 14
  • 23
user979974
  • 883
  • 3
  • 13
  • 32
  • Not so much a Linux user, but something looks wonky with `/home/rico/downloads/hgvs-0.1.2/Pygments-2.1.3-py2.7.egg (2.1.3)`. It's installed in your downloads folder? – roganjosh Oct 25 '18 at 08:09
  • Do you use virtualenv? The path pip tells you does seem very weird. My path shows me `/usr/lib/python3.7/site-packages`. Also, try `sudo pip install Pygments`, this should ignore the "installation" in your downloads folder. – Marcel P Oct 25 '18 at 08:16
  • @MarcelP doesn't that just install into the system python? – roganjosh Oct 25 '18 at 08:19
  • pip install Pygments ==> Requirement already satisfied: Pygments in home/rico/downloads/hgvs-0.1.2/Pygments-2.1.3-py2.7.egg (2.1.3). It says the same thing – user979974 Oct 25 '18 at 09:03
  • I don't use virtualenv. Should I use it? – user979974 Oct 25 '18 at 09:05
  • It should install into system, at least I understood it like that. virtualenv would _kinda_ explain the rather weird path. Did you try to remove it and install it again to see if it still resides in the same directory? – Marcel P Oct 25 '18 at 13:11

1 Answers1

2

It seems that you installed the Pygments module on the global scope instead of installing inside a virtualenv.

What is a virtual environment?

Virtual environments are a way to keep your dependencies inline for your app or service.
virtualenv is a tool to create isolated Python environments, in which you can now install dependencies specific for that environment rather than installing them globally.

Virtual environments help create consistency in your development and deployment process, which in turn will help build a better app or service.

Installing virtualenv

First, Install virtual env:

pip install virtualenv

To create a virtualenv first run this command:

$ virtualenv -p python3 {name-of-virtual-env} 

Lets call it my_venv, so ran the following command:

$ virtualenv -p python3 my_venv 

Once you create the virtual environment, run the following to activate it:

$ source my_venv/bin/activate 

After running the activate command you should see the name of your virtual env at the beginning of your terminal like this:

(my_venv) $ source my_venv/bin/activate 

Installing modules locally

Navigate inside the my_venv folder and install the Pygments module:

cd my_venv && pip3 install pygments

You should see it was installed localy under lib/python3.8/site-packages inside the my_venv folder:

`-- my_venv
    |-- bin
    |-- lib
    |   `-- python3.8
    |       `-- site-packages
    |           |-- chardet
    |           |-- chardet-3.0.4.dist-info
    |           |-- idna
    |           |-- pip
    |           |-- pip-21.0.1.dist-info
    |           |-- pip-21.0.1.virtualenv
    |           |-- pkg_resources
    |           |-- pygments #<--------- Here
    |           |-- pygments_promql            
    |           |-- pygments_promql-0.0.5.dist-info
    |           |-- regex
    `-- pyvenv.cfg

Deactivate virtualenv

When you are done running your app or service, you can shutdown your virtualenv by running the deactivate command:

(my_venv) $ deactivate

Read more in here.

Rot-man
  • 18,045
  • 12
  • 118
  • 124