impot d2l 是可以,但是from d2l import torch 就不行
Hey I translated your question to english and as far as I understood you have a problem to run the import statement. I had the same issue make sure that you install miniconda and create & activate the environment as described.
In my case the problem was that I did not use the correct python despite having activated the environment. Running ‘which python’ should return the python of your d2l environment. This github discussion led to the solution to me.
opened 01:29PM - 08 Dec 20 UTC
<!--
Hi! Read this; it's important.
This is an issue tracker for conda -- t… he package manager. File feature requests
for conda here, as well as bug reports about something conda has messed up.
Anaconda Community Code of Conduct: https://www.anaconda.com/community-code-of-conduct/
If your issue is a bug report for:
* a specific conda package from Anaconda ('defaults' channel):
==> file at https://github.com/ContinuumIO/anaconda-issues
* a specific conda package from conda-forge:
==> file at the corresponding feedstock under https://github.com/conda-forge
* repo.anaconda.com access and service:
==> file at https://github.com/ContinuumIO/anaconda-issues
* anaconda.org access and service:
==> file at https://anaconda.org/contact/report
* commands under 'conda build':
==> file at https://github.com/conda/conda-build
* commands under 'conda env':
==> please file it here!
* all other conda commands that start with 'conda':
==> please file it here!
If you continue on,
**please include all requested information below.**
If a maintainer determines the information is required to understand
your issue, and if it is not provided, your issue may be
closed automatically.
-->
## Current Behavior
<!-- What actually happens?
If you want to include console output, please use "Steps to Reproduce" below. -->
### Steps to Reproduce
1. Install and initialize system-wide Anaconda. "`(base)`" should be active on new bash instances.
1. Install `pyenv` after Anaconda, so that pyenv's `.bashrc` entries come _after_ the system-wide Anaconda `.bashrc` entries.
1. Install `python 3.6.9` using `pyenv`.
1. Install Miniconda separately.
1. Create a `python=3.6` environment using Miniconda.
1. With the `(base)` Anaconda environment active, try to then activate the Miniconda environment.
Result:
```bash
(base) joshua@XPS-15-9560:~$ which python
/home/joshua/.pyenv/shims/python
(base) joshua@XPS-15-9560:~$ source $SCT_DIR/python/etc/profile.d/conda.sh
(base) joshua@XPS-15-9560:~$ conda activate venv_sct
(venv_sct) joshua@XPS-15-9560:~$ which python
/home/joshua/.pyenv/shims/python # Incorrect result
```
## Expected Behavior
`python` should switch to the conda environment's python.
----
NB: I have some fixes for the problem that achieve the desired results, too. I can get the expected behavior in 2 ways:
If the `.bashrc` entries for Anaconda and pyenv are swapped:
```bash
(base) joshua@XPS-15-9560:~$ which python
/home/joshua/anaconda3/bin/python
(base) joshua@XPS-15-9560:~$ source $SCT_DIR/python/etc/profile.d/conda.sh
(base) joshua@XPS-15-9560:~$ conda activate venv_sct
(venv_sct) joshua@XPS-15-9560:~$ which python
/home/joshua/repos/spinalcordtoolbox/python/envs/venv_sct/bin/python # Expected result
```
If the `(base)` environment is deactivated first:
```bash
(base) joshua@XPS-15-9560:~$ which python
/home/joshua/.pyenv/shims/python
(base) joshua@XPS-15-9560:~$ conda deactivate
joshua@XPS-15-9560:~$ source $SCT_DIR/python/etc/profile.d/conda.sh
joshua@XPS-15-9560:~$ conda activate venv_sct
(venv_sct) joshua@XPS-15-9560:~$ which python
/home/joshua/repos/spinalcordtoolbox/python/envs/venv_sct/bin/python # Expected result
```
## Environment Information
<details open><summary><code>`conda info`</code></summary><p>
```
(base) joshua@XPS-15-9560:~$ conda info
active environment : base
active env location : /home/joshua/anaconda3
shell level : 1
user config file : /home/joshua/.condarc
populated config files : /home/joshua/.condarc
conda version : 4.9.2
conda-build version : 3.20.5
python version : 3.8.5.final.0
virtual packages : __cuda=11.0=0
__glibc=2.31=0
__unix=0=0
__archspec=1=x86_64
base environment : /home/joshua/anaconda3 (writable)
channel URLs : https://conda.anaconda.org/conda-forge/linux-64
https://conda.anaconda.org/conda-forge/noarch
https://repo.anaconda.com/pkgs/main/linux-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/r/linux-64
https://repo.anaconda.com/pkgs/r/noarch
package cache : /home/joshua/anaconda3/pkgs
/home/joshua/.conda/pkgs
envs directories : /home/joshua/anaconda3/envs
/home/joshua/.conda/envs
platform : linux-64
user-agent : conda/4.9.2 requests/2.24.0 CPython/3.8.5 Linux/5.4.0-58-generic ubuntu/20.04.1 glibc/2.31
UID:GID : 1000:1000
netrc file : None
offline mode : False
```
</p></details>
<details open><summary><code>`conda config --show-sources`</code></summary><p>
```
(base) joshua@XPS-15-9560:~$ conda config --show-sources
==> /home/joshua/.condarc <==
allow_conda_downgrades: True
channel_priority: strict
channels:
- conda-forge
- defaults
-
```
</p></details>
<details><summary><code>`conda list --show-channel-urls`</code></summary><p>
```
(base) joshua@XPS-15-9560:~$ conda list --show-channel-urls
# packages in environment at /home/joshua/anaconda3:
#
# Name Version Build Channel
_ipyw_jlab_nb_ext_conf 0.1.0 py38_0 defaults
_libgcc_mutex 0.1 main defaults
alabaster 0.7.12 py_0 defaults
anaconda 2020.11 py38_0 defaults
anaconda-client 1.7.2 py38_0 defaults
anaconda-navigator 1.10.0 py38_0 defaults
anaconda-project 0.8.4 py_0 defaults
argh 0.26.2 py38_0 defaults
argon2-cffi 20.1.0 py38h7b6447c_1 defaults
asn1crypto 1.4.0 py_0 defaults
astroid 2.4.2 py38_0 defaults
astropy 4.0.2 py38h7b6447c_0 defaults
async_generator 1.10 py_0 defaults
atomicwrites 1.4.0 py_0 defaults
attrs 20.3.0 pyhd3eb1b0_0 defaults
autopep8 1.5.4 py_0 defaults
babel 2.8.1 pyhd3eb1b0_0 defaults
backcall 0.2.0 py_0 defaults
backports 1.0 py_2 defaults
backports.functools_lru_cache 1.6.1 py_0 defaults
backports.shutil_get_terminal_size 1.0.0 py38_2 defaults
backports.tempfile 1.0 py_1 defaults
backports.weakref 1.0.post1 py_1 defaults
beautifulsoup4 4.9.3 pyhb0f4dca_0 defaults
bitarray 1.6.1 py38h27cfd23_0 defaults
bkcharts 0.2 py38_0 defaults
blas 1.0 mkl defaults
bleach 3.2.1 py_0 defaults
blosc 1.20.1 hd408876_0 defaults
bokeh 2.2.3 py38_0 defaults
boto 2.49.0 py38_0 defaults
bottleneck 1.3.2 py38heb32a55_1 defaults
brotlipy 0.7.0 py38h7b6447c_1000 defaults
bzip2 1.0.8 h7b6447c_0 defaults
ca-certificates 2020.10.14 0 defaults
cairo 1.14.12 h8948797_3 defaults
certifi 2020.6.20 pyhd3eb1b0_3 defaults
cffi 1.14.3 py38he30daa8_0 defaults
chardet 3.0.4 py38_1003 defaults
click 7.1.2 py_0 defaults
cloudpickle 1.6.0 py_0 defaults
clyent 1.2.2 py38_1 defaults
colorama 0.4.4 py_0 defaults
conda 4.9.2 py38h06a4308_0 defaults
conda-build 3.20.5 py38_1 defaults
conda-env 2.6.0 1 defaults
conda-package-handling 1.7.2 py38h03888b9_0 defaults
conda-verify 3.4.2 py_1 defaults
contextlib2 0.6.0.post1 py_0 defaults
cryptography 3.1.1 py38h1ba5d50_0 defaults
curl 7.71.1 hbc83047_1 defaults
cycler 0.10.0 py38_0 defaults
cython 0.29.21 py38he6710b0_0 defaults
cytoolz 0.11.0 py38h7b6447c_0 defaults
dask 2.30.0 py_0 defaults
dask-core 2.30.0 py_0 defaults
dbus 1.13.18 hb2f20db_0 defaults
decorator 4.4.2 py_0 defaults
defusedxml 0.6.0 py_0 defaults
diff-match-patch 20200713 py_0 defaults
distributed 2.30.1 py38h06a4308_0 defaults
docutils 0.16 py38_1 defaults
entrypoints 0.3 py38_0 defaults
et_xmlfile 1.0.1 py_1001 defaults
expat 2.2.10 he6710b0_2 defaults
fastcache 1.1.0 py38h7b6447c_0 defaults
filelock 3.0.12 py_0 defaults
flake8 3.8.4 py_0 defaults
flask 1.1.2 py_0 defaults
fontconfig 2.13.0 h9420a91_0 defaults
freetype 2.10.4 h5ab3b9f_0 defaults
fribidi 1.0.10 h7b6447c_0 defaults
fsspec 0.8.3 py_0 defaults
future 0.18.2 py38_1 defaults
get_terminal_size 1.0.0 haa9412d_0 defaults
gevent 20.9.0 py38h7b6447c_0 defaults
glib 2.66.1 h92f7085_0 defaults
glob2 0.7 py_0 defaults
gmp 6.1.2 h6c8ec71_1 defaults
gmpy2 2.0.8 py38hd5f6e3b_3 defaults
graphite2 1.3.14 h23475e2_0 defaults
greenlet 0.4.17 py38h7b6447c_0 defaults
gst-plugins-base 1.14.0 hbbd80ab_1 defaults
gstreamer 1.14.0 hb31296c_0 defaults
h5py 2.10.0 py38h7918eee_0 defaults
harfbuzz 2.4.0 hca77d97_1 defaults
hdf5 1.10.4 hb1b8bf9_0 defaults
heapdict 1.0.1 py_0 defaults
html5lib 1.1 py_0 defaults
icu 58.2 he6710b0_3 defaults
idna 2.10 py_0 defaults
imageio 2.9.0 py_0 defaults
imagesize 1.2.0 py_0 defaults
importlib-metadata 2.0.0 py_1 defaults
importlib_metadata 2.0.0 1 defaults
iniconfig 1.1.1 py_0 defaults
intel-openmp 2020.2 254 defaults
intervaltree 3.1.0 py_0 defaults
ipykernel 5.3.4 py38h5ca1d4c_0 defaults
ipython 7.19.0 py38hb070fc8_0 defaults
ipython_genutils 0.2.0 py38_0 defaults
ipywidgets 7.5.1 py_1 defaults
isort 5.6.4 py_0 defaults
itsdangerous 1.1.0 py_0 defaults
jbig 2.1 hdba287a_0 defaults
jdcal 1.4.1 py_0 defaults
jedi 0.17.1 py38_0 defaults
jeepney 0.5.0 pyhd3eb1b0_0 defaults
jinja2 2.11.2 py_0 defaults
joblib 0.17.0 py_0 defaults
jpeg 9b h024ee3a_2 defaults
json5 0.9.5 py_0 defaults
jsonschema 3.2.0 py_2 defaults
jupyter 1.0.0 py38_7 defaults
jupyter_client 6.1.7 py_0 defaults
jupyter_console 6.2.0 py_0 defaults
jupyter_core 4.6.3 py38_0 defaults
jupyterlab 2.2.6 py_0 defaults
jupyterlab_pygments 0.1.2 py_0 defaults
jupyterlab_server 1.2.0 py_0 defaults
keyring 21.4.0 py38_1 defaults
kiwisolver 1.3.0 py38h2531618_0 defaults
krb5 1.18.2 h173b8e3_0 defaults
lazy-object-proxy 1.4.3 py38h7b6447c_0 defaults
lcms2 2.11 h396b838_0 defaults
ld_impl_linux-64 2.33.1 h53a641e_7 defaults
libarchive 3.4.2 h62408e4_0 defaults
libcurl 7.71.1 h20c2e04_1 defaults
libedit 3.1.20191231 h14c3975_1 defaults
libffi 3.3 he6710b0_2 defaults
libgcc-ng 9.1.0 hdf63c60_0 defaults
libgfortran-ng 7.3.0 hdf63c60_0 defaults
liblief 0.10.1 he6710b0_0 defaults
libllvm10 10.0.1 hbcb73fb_5 defaults
libpng 1.6.37 hbc83047_0 defaults
libsodium 1.0.18 h7b6447c_0 defaults
libspatialindex 1.9.3 he6710b0_0 defaults
libssh2 1.9.0 h1ba5d50_1 defaults
libstdcxx-ng 9.1.0 hdf63c60_0 defaults
libtiff 4.1.0 h2733197_1 defaults
libtool 2.4.6 h7b6447c_1005 defaults
libuuid 1.0.3 h1bed415_2 defaults
libxcb 1.14 h7b6447c_0 defaults
libxml2 2.9.10 hb55368b_3 defaults
libxslt 1.1.34 hc22bd24_0 defaults
llvmlite 0.34.0 py38h269e1b5_4 defaults
locket 0.2.0 py38_1 defaults
lxml 4.6.1 py38hefd8a0e_0 defaults
lz4-c 1.9.2 heb0550a_3 defaults
lzo 2.10 h7b6447c_2 defaults
markupsafe 1.1.1 py38h7b6447c_0 defaults
matplotlib 3.3.2 0 defaults
matplotlib-base 3.3.2 py38h817c723_0 defaults
mccabe 0.6.1 py38_1 defaults
mistune 0.8.4 py38h7b6447c_1000 defaults
mkl 2020.2 256 defaults
mkl-service 2.3.0 py38he904b0f_0 defaults
mkl_fft 1.2.0 py38h23d657b_0 defaults
mkl_random 1.1.1 py38h0573a6f_0 defaults
mock 4.0.2 py_0 defaults
more-itertools 8.6.0 pyhd3eb1b0_0 defaults
mpc 1.1.0 h10f8cd9_1 defaults
mpfr 4.0.2 hb69a4c5_1 defaults
mpmath 1.1.0 py38_0 defaults
msgpack-python 1.0.0 py38hfd86e86_1 defaults
multipledispatch 0.6.0 py38_0 defaults
navigator-updater 0.2.1 py38_0 defaults
nbclient 0.5.1 py_0 defaults
nbconvert 6.0.7 py38_0 defaults
nbformat 5.0.8 py_0 defaults
ncurses 6.2 he6710b0_1 defaults
nest-asyncio 1.4.2 pyhd3eb1b0_0 defaults
networkx 2.5 py_0 defaults
nltk 3.5 py_0 defaults
nose 1.3.7 py38_2 defaults
notebook 6.1.4 py38_0 defaults
numba 0.51.2 py38h0573a6f_1 defaults
numexpr 2.7.1 py38h423224d_0 defaults
numpy 1.19.2 py38h54aff64_0 defaults
numpy-base 1.19.2 py38hfa32c7d_0 defaults
numpydoc 1.1.0 pyhd3eb1b0_1 defaults
olefile 0.46 py_0 defaults
openpyxl 3.0.5 py_0 defaults
openssl 1.1.1h h7b6447c_0 defaults
packaging 20.4 py_0 defaults
pandas 1.1.3 py38he6710b0_0 defaults
pandoc 2.11 hb0f4dca_0 defaults
pandocfilters 1.4.3 py38h06a4308_1 defaults
pango 1.45.3 hd140c19_0 defaults
parso 0.7.0 py_0 defaults
partd 1.1.0 py_0 defaults
patchelf 0.12 he6710b0_0 defaults
path 15.0.0 py38_0 defaults
path.py 12.5.0 0 defaults
pathlib2 2.3.5 py38_0 defaults
pathtools 0.1.2 py_1 defaults
patsy 0.5.1 py38_0 defaults
pcre 8.44 he6710b0_0 defaults
pep8 1.7.1 py38_0 defaults
pexpect 4.8.0 py38_0 defaults
pickleshare 0.7.5 py38_1000 defaults
pillow 8.0.1 py38he98fc37_0 defaults
pip 20.2.4 py38h06a4308_0 defaults
pixman 0.40.0 h7b6447c_0 defaults
pkginfo 1.6.1 py38h06a4308_0 defaults
pluggy 0.13.1 py38_0 defaults
ply 3.11 py38_0 defaults
prometheus_client 0.8.0 py_0 defaults
prompt-toolkit 3.0.8 py_0 defaults
prompt_toolkit 3.0.8 0 defaults
psutil 5.7.2 py38h7b6447c_0 defaults
ptyprocess 0.6.0 py38_0 defaults
py 1.9.0 py_0 defaults
py-lief 0.10.1 py38h403a769_0 defaults
pycodestyle 2.6.0 py_0 defaults
pycosat 0.6.3 py38h7b6447c_1 defaults
pycparser 2.20 py_2 defaults
pycurl 7.43.0.6 py38h1ba5d50_0 defaults
pydocstyle 5.1.1 py_0 defaults
pyflakes 2.2.0 py_0 defaults
pygments 2.7.2 pyhd3eb1b0_0 defaults
pylint 2.6.0 py38_0 defaults
pyodbc 4.0.30 py38he6710b0_0 defaults
pyopenssl 19.1.0 py_1 defaults
pyparsing 2.4.7 py_0 defaults
pyqt 5.9.2 py38h05f1152_4 defaults
pyrsistent 0.17.3 py38h7b6447c_0 defaults
pysocks 1.7.1 py38_0 defaults
pytables 3.6.1 py38h9fd0a39_0 defaults
pytest 6.1.1 py38_0 defaults
python 3.8.5 h7579374_1 defaults
python-dateutil 2.8.1 py_0 defaults
python-jsonrpc-server 0.4.0 py_0 defaults
python-language-server 0.35.1 py_0 defaults
python-libarchive-c 2.9 py_0 defaults
pytz 2020.1 py_0 defaults
pywavelets 1.1.1 py38h7b6447c_2 defaults
pyxdg 0.27 pyhd3eb1b0_0 defaults
pyyaml 5.3.1 py38h7b6447c_1 defaults
pyzmq 19.0.2 py38he6710b0_1 defaults
qdarkstyle 2.8.1 py_0 defaults
qt 5.9.7 h5867ecd_1 defaults
qtawesome 1.0.1 py_0 defaults
qtconsole 4.7.7 py_0 defaults
qtpy 1.9.0 py_0 defaults
readline 8.0 h7b6447c_0 defaults
regex 2020.10.15 py38h7b6447c_0 defaults
requests 2.24.0 py_0 defaults
ripgrep 12.1.1 0 defaults
rope 0.18.0 py_0 defaults
rtree 0.9.4 py38_1 defaults
ruamel_yaml 0.15.87 py38h7b6447c_1 defaults
scikit-image 0.17.2 py38hdf5156a_0 defaults
scikit-learn 0.23.2 py38h0573a6f_0 defaults
scipy 1.5.2 py38h0b6359f_0 defaults
seaborn 0.11.0 py_0 defaults
secretstorage 3.1.2 py38_0 defaults
send2trash 1.5.0 py38_0 defaults
setuptools 50.3.1 py38h06a4308_1 defaults
simplegeneric 0.8.1 py38_2 defaults
singledispatch 3.4.0.3 py_1001 defaults
sip 4.19.13 py38he6710b0_0 defaults
six 1.15.0 py38h06a4308_0 defaults
snowballstemmer 2.0.0 py_0 defaults
sortedcollections 1.2.1 py_0 defaults
sortedcontainers 2.2.2 py_0 defaults
soupsieve 2.0.1 py_0 defaults
sphinx 3.2.1 py_0 defaults
sphinxcontrib 1.0 py38_1 defaults
sphinxcontrib-applehelp 1.0.2 py_0 defaults
sphinxcontrib-devhelp 1.0.2 py_0 defaults
sphinxcontrib-htmlhelp 1.0.3 py_0 defaults
sphinxcontrib-jsmath 1.0.1 py_0 defaults
sphinxcontrib-qthelp 1.0.3 py_0 defaults
sphinxcontrib-serializinghtml 1.1.4 py_0 defaults
sphinxcontrib-websupport 1.2.4 py_0 defaults
spyder 4.1.5 py38_0 defaults
spyder-kernels 1.9.4 py38_0 defaults
sqlalchemy 1.3.20 py38h7b6447c_0 defaults
sqlite 3.33.0 h62c20be_0 defaults
statsmodels 0.12.0 py38h7b6447c_0 defaults
sympy 1.6.2 py38h06a4308_1 defaults
tbb 2020.3 hfd86e86_0 defaults
tblib 1.7.0 py_0 defaults
terminado 0.9.1 py38_0 defaults
testpath 0.4.4 py_0 defaults
threadpoolctl 2.1.0 pyh5ca1d4c_0 defaults
tifffile 2020.10.1 py38hdd07704_2 defaults
tk 8.6.10 hbc83047_0 defaults
toml 0.10.1 py_0 defaults
toolz 0.11.1 py_0 defaults
tornado 6.0.4 py38h7b6447c_1 defaults
tqdm 4.50.2 py_0 defaults
traitlets 5.0.5 py_0 defaults
typing_extensions 3.7.4.3 py_0 defaults
ujson 4.0.1 py38he6710b0_0 defaults
unicodecsv 0.14.1 py38_0 defaults
unixodbc 2.3.9 h7b6447c_0 defaults
urllib3 1.25.11 py_0 defaults
watchdog 0.10.3 py38_0 defaults
wcwidth 0.2.5 py_0 defaults
webencodings 0.5.1 py38_1 defaults
werkzeug 1.0.1 py_0 defaults
wheel 0.35.1 py_0 defaults
widgetsnbextension 3.5.1 py38_0 defaults
wrapt 1.11.2 py38h7b6447c_0 defaults
wurlitzer 2.0.1 py38_0 defaults
xlrd 1.2.0 py_0 defaults
xlsxwriter 1.3.7 py_0 defaults
xlwt 1.3.0 py38_0 defaults
xmltodict 0.12.0 py_0 defaults
xz 5.2.5 h7b6447c_0 defaults
yaml 0.2.5 h7b6447c_0 defaults
yapf 0.30.0 py_0 defaults
zeromq 4.3.3 he6710b0_3 defaults
zict 2.0.0 py_0 defaults
zipp 3.4.0 pyhd3eb1b0_0 defaults
zlib 1.2.11 h7b6447c_3 defaults
zope 1.0 py38_1 defaults
zope.event 4.5.0 py38_0 defaults
zope.interface 5.1.2 py38h7b6447c_0 defaults
zstd 1.4.5 h9ceee32_0 defaults
```
</p></details>
┆Issue is synchronized with this [Jira Task](https://anaconda.atlassian.net/browse/CONDAORG-307)
‘… Now, this doesn’t occur if the .bashrc entries for Anaconda and pyenv are swapped:…’
So I swapped the entries and then I had the correct python version.
2 Likes