This might be a bug, but: if I create a virtualenv while using a Pipenv environment that virtualenv always has access to site packages for that Pipenv environment.
$ pipenv install numpy
Creating a virtualenv for this project…
...
$ pipenv run python -m venv venv # Default behaviour is not to allow access to site-packages
$ source venv/bin/activate
(venv) $ python
Python 3.7.2 (default, May 1 2019, 12:27:28)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>>
Why is this happening?
Can I avoid it?
Related
I have python3.7 installed but also python3.4. For example:
$ python3
Python 3.4.3 (default, Nov 12 2018, 22:25:49)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
And:
$ python3.7
Python 3.7.0 (default, Jun 28 2018, 00:00:00)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
How can I install packages to python3.7 ? Any pip3 command I use goes to python3.4 and I'm not sure how to install anything for python3.7. Any ideas? Even running something like this doesn't work:
$ python3.7 -m ensurepip --upgrade
/usr/bin/python3.7: No module named ensurepip
Or:
$ sudo python3.7 -m pip install PyMySQL
register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
I don't know whether this may be an appropriate solution for you. But this is what I generally follow.
Just install Anaconda in your system and create different environments according to your needs.
For your case create two different environments one for Python 3.4.3 and another for Python 3.7 using the following command
conda create --name py34 python=3.4.3 and
conda create --name py37 python=3.7
//This lines will create two new environments named py34 and py37
You then install libraries according to your needs in the respective environment. Now you can work into each environment without interfering with the libraries of the other environment.
To use anaconda kindly follow Anaconda cheatsheet. You will get everything that you need.
Hope this will help you.
This might help : It addresses the same issue as yours. In short, try
python3.7 -m pip install pip
Here's a reference documentation
I am running Ubuntu Linux 18.04 on Virtual box,
I have installed tensorflow properly in venv and import works fine and also
I could run some sample programs with tensorflow, but when i try help(tf) python prompt as show below in the logs, I am hitting coredump,
`(venv) shiv#shiv-vbox:~/TF$ python
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> x=0
>>> help(x)
>>> help(tf)
Segmentation fault (core dumped)`
Is something wrong with my installation? i tried multiple times to install to confirm some issue with install but all the time I am getting cordump when I do help(tf), any inputs on this would be helpful.
-Thank you
update
I followed following steps to install
shiv#shiv-vbox:~/TF$ sudo virtualenv --system-site-packages -p python3 ./venv
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/shiv/TF/venv/bin/python3
Also creating executable in /home/shiv/TF/venv/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
shiv#shiv-vbox:~/TF$ source ./venv/bin/activate
(venv) shiv#shiv-vbox:~/TF$
(venv) shiv#shiv-vbox:~/TF$ ls
Tflow venv
(venv) shiv#shiv-vbox:~/TF$ pip install --upgrade pip
Requirement already up-to-date: pip in ./venv/lib/python3.6/site-packages (18.1)
(venv) shiv#shiv-vbox:~/TF$ pip install tensorflow
My system is running MacOS and Homebrew and it recently updated to Python 3.7.
Now, just creating a new virtualenv and trying to use it fails.
FYI, I don't actually need Python 3.7. I didn't upgrade on purpose. I'd prefer the latest stable, supported version, but of course, I want the basics working.
➜ rm -rf ~/.virtualenvs/test
➜ python3 -m venv ~/.virtualenvs/test
➜ vex --path ~/.virtualenvs/test python
zsh: /usr/local/bin/vex: bad interpreter: /usr/local/opt/python/bin/python3.6: no such file or directory
➜ python3
Python 3.7.0 (default, Jun 29 2018, 20:13:13)
[Clang 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
/usr/local/bin/vex file has this as the first line: #!/usr/local/opt/python/bin/python3.6; it's called shebang and it points operating system to the interpreter to run the script. You've uninstalled python3.6 so OS cannot find said interpreter. You need to reinstall vex with python3.7.
I am using python3 in CentOS and I was able to install pandas using pip3, but when I do import pandas in python3, it throws import error: no module named pandas.
There are many reasons to not install packages through pip only, one is that you may end up installing them globally, meaning you either wont be able or will have trouble using two different versions of the same package.
It's better to let each project have it's own dependencies, if something goes really (really) wrong you'll just nuke your project environment without hurting other projects. One of the most acceptable ways of doing this is by using virtual environments.
With virtualenv
To create a virtualenv
$ virtualenv ENV
Then activate it
$ source bin/activate
Now install pandas
$ pip install pandas
To leave the environment:
$ deactivate
With pipenv
You can also combine pyenv (which lets you install different Python versions) with pipenv.
Example:
# creating a directory for my project
$ mkdir pandas-env && cd pandas-env
# creating an environment with Python 3.6.4
$ pipenv --python 3.6.4
# installing pandas in your environment
$ pipenv install pandas
# enter your environment
$ pipenv shell
# and check your python version, it's probably different
# from the older system's version
$ python
Python 3.6.4 (default, Mar 6 2018, 10:29:06)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
# now import pandas
>>> import pandas as pd
>>>
To leave your environment just press CTL+D.
I'm on ubuntu 14.04. Python 3.4 was present already, I additionally installed python 3.6.
Python 3.6 seemingly runs fine:
...:/usr/bin$ python3.6
Python 3.6.3 (default, Oct 6 2017, 00:00:00)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
pip3 also runs fine, but for python 3.6.4 (as expected):
...:/usr/bin$ pip3 -V
pip 9.0.1 from /usr/local/lib/python3.4/dist-packages (python 3.4)
So I tried running pip3 under python 3.6, but no luck:
...:/usr/bin$ python3.6 -m pip3 -V
/usr/bin/python3.6: No module named pip3
When searching I found a couple of suggestioons aroundthat error message, but they were all about pip3 not working at all, which is not my problem.
What am I getting wrong?