I have installed mapnik 3.0.12 with conda install -c mrterry mapnik, but why I can`t import it in my code?
import mapnik
ModuleNotFoundError: No module named 'mapnik'
I looked in anaconda3/pkgs/mapnik-3.0.12-0/lib and there is no python3.7 folder there, only .so and .a files.
I have installed mapnik with sudo apt install python3-mapnik in ubuntu 18.04 and it imports well with /usr/bin/python3 interpreter. And in directory /usr/lib/python3/dist-packages/mapnik there is some .py files.
I'm not familiar with the tool, but it looks like Mapnik is a C++ library that has separate Python bindings. You need to install both mapnik and python-mapnik. Only Python 2 is supported, so you need to create a new env for this.
Conda (only if you trust the channel)
A search of Anaconda Cloud shows only linux-64 platform is available and only from user channels. I'm following your lead on using the mrterry channel, but generally I will only use a channel if I trust the user/org.
conda create -n myenv -c mrterry python=2.7 mapnik python-mapnik
Recommended Approach
Since I don't recognize any of the channels in the search, personally I would just follow the official install instructions. First, I would set up a Conda env with Python 2.7 and the dependencies that Mapnik lists. Then activate that env, and proceed with following the instructions (./configure, make, etc.).
Related
I can not use Mumpy with Ubuntu, Python 3.9 in Anaconda. But I have installed it. How can I fix this?
Part of the point of virtual environments, like those created by conda, are that you don't need root ("administrator") privileges to build and install software, so you shouldn't need sudo; just run python setup.py develop. You may need other things installed (compilers and development libraries) for that to work.
You've already confirmed numpy is installed via your conda install and pip install commands, but you could also run python -c "import numpy; print(numpy.__version__)" as further confirmation that it's working.
Pytorch is already packaged for conda - have you tried the command listed at that link?
could you help me with followings.
paramiko 16.1.0 library is in [python default] /usr/local/lib/python2.7/site-packages
But I can not upgrade paramiko 16.1.0 library to current paramiko 2.8.0 library; so I had to download paramiko 2.8.0 library into my path /home/pylib
Please let me know how I can force python to use /home/pylib/paramiko [paramiko 2.8.0 library] in my python code
Note: for now I am stuck with Python 2.7;I can not update PYTHONPATH
It's good practice to use virtual environments to avoid conflicts like this.
What is a virtual environment?
A virtual environment is basically like creating a fresh installation of Python for only one project. This allows you to easily have two different versions of a library installed for different projects.
How do I use virtual environments?
Install the virtualenv package: pip2 install virtualenv
Go to the root of your project cd path/to/project/root
Create a virtualenv: virtualenv -p /usr/bin/python2 venv
Activate the environment: . venv/bin/activate
Install the package version you want: pip2 install paramiko==2.8.0
Run your program: python something.py
To exit the virtual environment use: deactivate
Next time you want to run your program make sure you activate the environment with . venv/bin/activate first. None of the other steps need to be repeated.
I have the following version of python
import sys
print(sys.version)
3.6.5 | packaged by conda-forge | (default, Apr 6 2018, 13:44:09)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)]
I installed a package with the following command
pip install wfdb
It is succesfully installed because when I then write the command:
pip show wfdb
The following information appears
Location:
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
However, when I type the command import wfdb in Python notebook or the version of python in terminal, I get the following message
No module named 'wfdb'
Does it have to do with the path on which python is checking where the packages are? How to check this and how to change it?
You have (at least) 2 Python installations, one managed by Anaconda, the other what appears to be an official Python.org Mac build installed system-wide. The pip command on the command-line is the one tied to the Python.org Mac build.
pip is a script that is tied to a specific Python installation, and there can be multiple versions of the script installed in different locations, and is usually also installed with pipX and pipX.Y to match the X.Y version indicator of the Python version it is tied to. For Python 3.6, that means the same script would also be available as pip3 and pip3.6. (This also means that pip can be connected to Python 2 or Python 3, depending on your exact OS setup. It is not a given that pip, without a version number, installs into Python 2.x as some answers may claim).
Note that when you run a command without a path in your shell, (such as pip as opposed to /usr/bin/pip), you are asking your shell to find the command for you in a number of locations, listed in the PATH environment variable. The first location in the PATH list with that command is then fixed. which -a <command> would tell you all possible PATH-registered locations that the command can be found in. You can always use the full path to a command to bypass the PATH search path.
You can always verify what Python version the pip command is connected to with:
pip -V
which will output the version of pip and the location it is installed with. It'll print something like
pip pipX.pipY path/to/pythonX.Y/site-packages/pip (python X.Y)
where pipX.pipY is the pip version number and path/to/pythonX.Y tells you what Python installation this is for.
You can try to match this with the Python version by running
python -m site
which outputs the Python module search path for that Python version. Python can be run with python, pythonX and pythonX.Y too, and is subject to the same PATH search.
Note the -m switch there, that instructs Python to find a module in it's module search path and execute it as a script. Loads of modules support being run that way, including pip. This is important as that helps avoid having to search for a better pip command if you already can start the right Python version.
You have several good options here:
Since you are using Anaconda, you could look for a conda package for the same project. There is such a package for wfdb. Install it with
conda install wfdb
Anaconda aims to give you a wider software management experience that includes a broader set of software options than just the Python PyPI ecosystem, and conda packages usually manage more things than just the Python package.
Conda packages are usually maintained by a different set of developers from the package itself, so there may be a newer version available on PyPI (requiring pip install) than there is on Conda.
This is not an option for all Python packages, if there is no conda package you have to use pip. See Installing non-conda packages.
you can use the conda command to create a conda environment. Once you have an environment created, you can activate it with
source activate <name_of_cenv>
to alter your PATH settings. With the envirnoment 'active' the first directory listed on your PATH is the one for the conda environment and the pip command will be the one tied to that environment.
Note that a conda environment gives you an isolated environment for a specific project, keeping the library installation separate from the rest of your Python packages in the central site-packages location. If you want to install a package for all of your Anaconda Python projects, don't use a conda environment.
Use the Anaconda Python binary to run pip as a module; when you can run /path/to/python or pythoncommand to open the right Python version, you can use that same path to run /path/to/python -m pip ... instead of pip ... to be absolutely certain you are installing into the correct Python version.
Look for a better pip command, with which -a pip or which -a pip3.6, etc. But if you already know the Python binary, look in the same bin location for pip. If you have anaconda/bin/python, then there probably is a anaconda/bin/pip too.
As you can read here:
pip3 and pip would make a difference only when you are not using any
environment managers like virualenv (or) conda. Now as you are
creating a conda environment which has python==3.x, pip would be
equivalent to pip3.
For this reason it could be you did not activate your Conda environment before installing required packages and running your code.
Activate the new environment:
On Windows:
activate myenv
On macOS (this should be your option) and Linux:
source activate myenv
NOTE: Replace myenv with the name of the environment.
which python
gives the you the PATH to python
and then /path/to/python -m pip install thepackagetobeinstalled
Many thanks #MartijnPieters
You have installed python2.x package and you're using python3.x. Try:
pip3 install wfdb
If you don't have pip3 run:
[apt-get/yum] install python3-pip
You can see what packages you have currently installed by running:
pip freeze
and for python 3.x packages
pip3 freeze
Please remember each time you install a Python package, it will be placed in the directory for one particular Python version. Hence your error.
I am working on a project in python on a Debian 8 VM. To work on the project further I need to install matplotlib 1.5.1. When I attempt to upgrade the current version (obtained through apt-get) or install I am told that I need freetype and png. When I go to install freetype using this link:
http://www.linuxfromscratch.org/blfs/view/svn/general/freetype2.html
After installing and entering the proper commands, I go to try to install matplotlib again and receive the same error.
I tried to install Anaconda3 because it comes with freetype and basically every package that I need for my project. But after running the .sh file I was unable to change my python to use anaconda as the interpreter. How can I do this?
Thanks!
[UPDATE]
I am having to go into my anaconda3 file, then run source bin/activate ~/anaconda3/ Is there anyway to create an alias that would do all this?
You have to first create a conda python environment:
/path/to/conda/bin/conda create --name myenv python=3
(see http://conda.pydata.org/docs/using/envs.html)
When the environment has been created you simply activate it as follows:
/path/to/conda/bin/source activate myenv
Thereafter the system will run python from the conda environment you specified and not from the standard location.
First, please bear with me. I have hard time telling others my problem and this is a long thread...
I am using pythonbrew to run multiple versions of python in Ubuntu 10.10.
For installing pythonbrew and how it works, please refers to this link below
http://www.howopensource.com/2011/05/how-to-install-and-manage-different-versions-of-python-in-linux/
After reading a couple stackoverflow threads, I finally found the file called Setup under this directory: ~/.pythonbrew/pythons/Python-2.7.1/lib/python2.7/config
In this Setup file I see
# Andrew Kuchling's zlib module.
# This require zlib 1.1.3 (or later).
# See http://www.gzip.org/zlib/
# zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
I uncommented the last line, then I ran python -v again. However, I received the same error when I tried import zlib, so I guess I have to do something to install zlib into the lib.
But I am clueless about what I need to do. Can someone please direct me in the right direction??? Thank you very much!
I am doing this because I want to use different version of python in different virtualenv I created.
When I did virtualenv -p python2.7 I received no module named zlib.
jwxie518#jwxie518-P5E-VM-DO:~$ virtualenv -p python2.7 --no-site-packages testenv
Running virtualenv with interpreter /home/jwxie518/.pythonbrew/pythons/Python-2.7.1/bin/python2.7
Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 17, in <module>
import zlib
ImportError: No module named zlib
EDIT
I have to install 2.7.1 by appending --force.
I am developing Django, and I need some of these missing modules, for example sqlite3, and to create my virtualenv I definitely need zlib. If I just use the system default (2.6.6), I have no problem.
To do this with system default, all I need to do is
virtualenv --no-site-packages testenv
Thanks!
(2nd edit)
I installed 3.2 also and I tested it without problem, so I guess my problem comes down to how to install the missing module(s).
jwxie518#jwxie518-P5E-VM-DO:~$ virtualenv -p python3.2 testenv
Running virtualenv with interpreter /home/jwxie518/.pythonbrew/pythons/Python-3.2/bin/python3.2
New python executable in testenv/bin/python3.2
Also creating executable in testenv/bin/python
Installing distribute..................................................................................................................................................................................................................................................................................................................................done.
Installing pip...............done.
jwxie518#jwxie518-P5E-VM-DO:~$ virtualenv -p python3.2 --no-site-packages testenv
Running virtualenv with interpreter /home/jwxie518/.pythonbrew/pythons/Python-3.2/bin/python3.2
New python executable in testenv/bin/python3.2
Also creating executable in testenv/bin/python
Installing distribute..................................................................................................................................................................................................................................................................................................................................done.
Installing pip...............done.
Sounds like you need to install the devel package for zlib, probably want to do something like
# ubuntu 12,14,16,18,20.04+
sudo apt-get install zlib1g-dev
Instead of using python-brew you might want to consider just compiling by hand, it's not very hard. Just download the source, and configure, make, make install. You'll want to at least set --prefix to somewhere, so it'll get installed where you want.
./configure --prefix=/opt/python2.7 + other options
make
make install
You can check what configuration options are available with ./configure --help and see what your system python was compiled with by doing:
python -c "import sysconfig; print sysconfig.get_config_var('CONFIG_ARGS')"
The key is to make sure you have the development packages installed for your system, so that Python will be able to build the zlib, sqlite3, etc modules. The python docs cover the build process in more detail: http://docs.python.org/using/unix.html#building-python.
By default when you configuring Python source, zlib module is disabled, so you can enable it using option --with-zlib when you configure it. So it becomes
./configure --with-zlib
For the case I met, I found there are missing modules after make. So I did the following:
install zlib-devel
make and install python again.
After running configure, you can change the config option in the file Modules/Setup as below:
zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
Or you can uncomment the zlib line as-is.
I had a lot of problems making a virtual environment (venv) as described in the tensorflow installation guide.
Most of the commands listed in this post didn't help me either so, if this is also your case this is what I did:
pip3 install --user pipenv
pip install virtualenv
Installs the dependencies to create a virtual environment
mkdir myenv
Makes a new directory called myenv but you can call it whatever you want e.g. mynewenv
cd myenv
Or whatever you call your directory so: cd [your_directory_name]
virtualenv -p /usr/bin/python3 venv
Creates a virtual environment called venv in the folder myenv. You can call your virtual env whatever you like e.g. vitualenv [v_env_name]
source ./venv/bin/activate
Activates the virtual environment. Note that if you choose a different v. env. name your commands should be written as such source ./[v_env_name]/bin/activate
deactivate
Deactivates the virtual environment.
Note: I am using Python 3.6.6 & Ubuntu 18.04
source for the commands
After you install the missing zlib dev package you can also use pythonbrew to uninstall and then reinstall the version of python you wanted and it seems like it picks up the new package to compile to correct abilities. This way you can keep using pythonbrew and don't have to do the compilation yourself (though it isn't that difficult)
Similar to the answers here on CentOS or RHEL run
sudo yum install zlib-devel
The --with-zlib solutions shown here seem to be missing headers that Python 3.9 and up needs to link (in my case).
The easiest solution I found, is given on python.org devguide:
sudo apt-get build-dep python3.6
If that package is not available for your system, try reducing the minor version until you find a package that is available in your system’s package manager.
I tried explaining details, on my blog.
My objective was to create a new Django project from the command line in Ubuntu, like so:
django-admin.py startproject mysite
I have python2.7.5 installed. I got this error:
ImportError: No module named zlib
For hours I could not find a solution, until now!
Here is a link to the solution -
http://doc.biblissima-condorcet.fr/loris-setup-guide-ubuntu-debian
I followed and executed instruction in Section 1.1 and it is working perfectly! It is an easy solution.