teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

間違いの修正

2020/07/22 10:11

投稿

taniyan
taniyan

スコア11

title CHANGED
File without changes
body CHANGED
@@ -99,14 +99,14 @@
99
99
 
100
100
  ## エラーの説明
101
101
 
102
- **◆Error when importing Numpy**
102
+ **◆Numpyをimportした時、下記のエラー内容が出ます。**
103
103
  ```
104
104
  /Users/username/.pyenv/versions/anaconda3-5.0.1/envs/your_env_name/bin
105
105
  /Users/username/.pyenv/versions/anaconda3-5.0.1/envs/your_env_name/lib/python3.8/site-packages/numpy/__init__.py:140: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
106
106
  from . import _distributor_init
107
107
  pModule is empty!!!
108
108
  Traceback (most recent call last):
109
- File "/Users/username/git/python_c_api_sample/tanitani.py", line 10, in <module>
109
+ File "/Users/username/git/python_c_api_sample/python_code_sample.py", line 10, in <module>
110
110
  import numpy as np
111
111
  File "/Users/username/.pyenv/versions/anaconda3-5.0.1/envs/your_env_name/lib/python3.8/site-packages/numpy/__init__.py", line 142, in <module>
112
112
  from . import core
@@ -138,7 +138,7 @@
138
138
  in /Users/username/.pyenv/versions/anaconda3-5.0.1/envs/your_env_name/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so
139
139
 
140
140
  ```
141
- **◆Error when importing random**
141
+ **◆randomをimportした時、下記のエラー内容が出ます。(pythonファイルの2行目を修正してください)**
142
142
 
143
143
  ```
144
144
  File "./python_code_sample.py", line 2, in <module>
@@ -186,7 +186,7 @@
186
186
 
187
187
  ## cコンパイル
188
188
  ```
189
- g++ -fPIC main.cpp $(python3.8-config --cflags --ldflags) -lpython3.8 -o main && ./main
189
+ g++ -fPIC main.cpp $(python3.8-config --cflags --ldflags) -lpython3.8
190
190
 
191
191
  python3.8-config --cflags
192
192
  -I/Users/username/.pyenv/versions/anaconda3-5.0.1/envs/your_env_name/include/python3.8 -I/Users/username/.pyenv/versions/anaconda3-5.0.1/envs/your_env_name/include/python3.8 -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/username/.pyenv/versions/anaconda3-5.0.1/envs/your_env_name/include -arch x86_64 -I/Users/username/.pyenv/versions/anaconda3-5.0.1/envs/your_env_name/include -arch x86_64

1

書式の改善

2020/07/22 10:11

投稿

taniyan
taniyan

スコア11

title CHANGED
File without changes
body CHANGED
@@ -13,19 +13,19 @@
13
13
  ご教授いただけると幸いです。
14
14
 
15
15
  本投稿は次のように構成にしました
16
- ◆コード
17
- ◆エラーの説明
18
- ◆環境情報
19
- ◆コードを動かすために
20
-  -ディレクトリの作成
21
-  -作成されたpython環境
22
-  -コンパイル
23
16
 
24
- ```
25
- #コード
17
+ - ◆コード
18
+ - ◆エラーの説明
19
+ - ◆環境情報
20
+ - ◆コードを動かすために
21
+    -ディレクトリの作成
22
+    -作成されたpython環境
23
+    -コンパイル
26
24
 
27
- ◆main.cpp
28
25
 
26
+ ## コード
27
+ **◆main.cpp**
28
+ ```
29
29
  #include <Python.h>
30
30
  #include <iostream>
31
31
  #include <stdio.h>
@@ -78,11 +78,9 @@
78
78
 
79
79
  return 0;
80
80
  }
81
-
82
- ------------------------
81
+ ```
83
-
84
- ◆python_code_sample.py
82
+ **◆python_code_sample.py**
85
-
83
+ ```
86
84
  import numpy as np
87
85
  #import random
88
86
  print("hoge1")
@@ -99,11 +97,10 @@
99
97
  print(sample_test())
100
98
  ```
101
99
 
100
+ ## エラーの説明
101
+
102
+ **◆Error when importing Numpy**
102
103
  ```
103
- #エラーの説明
104
-
105
- ◆Error when importing Numpy
106
-
107
104
  /Users/username/.pyenv/versions/anaconda3-5.0.1/envs/your_env_name/bin
108
105
  /Users/username/.pyenv/versions/anaconda3-5.0.1/envs/your_env_name/lib/python3.8/site-packages/numpy/__init__.py:140: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
109
106
  from . import _distributor_init
@@ -140,9 +137,10 @@
140
137
  Expected in: flat namespace
141
138
  in /Users/username/.pyenv/versions/anaconda3-5.0.1/envs/your_env_name/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so
142
139
 
140
+ ```
141
+ **◆Error when importing random**
143
142
 
144
- ◆Error when importing random
143
+ ```
145
-
146
144
  File "./python_code_sample.py", line 2, in <module>
147
145
  import random
148
146
  File "/Users/username/.pyenv/versions/anaconda3-5.0.1/envs/your_env_name/lib/python3.8/random.py", line 41, in <module>
@@ -153,36 +151,41 @@
153
151
  in /Users/username/.pyenv/versions/anaconda3-5.0.1/envs/your_env_name/lib/python3.8/lib-dynload/math.cpython-38-darwin.so
154
152
  ```
155
153
 
156
- ```
157
- # 環境情報
154
+ ## 環境情報
158
155
  I installed anaconda in pyenv.
159
156
  I created the environment as follows.
160
- Anaconda installer is anaconda3-5.0.1
161
- python3.8.1
162
- macOS(Catalina version:10.15.4)
163
- output is g++ -v
164
-  Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
165
-  Apple clang version 11.0.3 (clang-1103.0.32.59)
166
-  Target: x86_64-apple-darwin19.4.0
167
-  Thread model: posix
168
-  InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
157
+ - Anaconda installer is anaconda3-5.0.1
158
+ - python3.8.1
159
+ - macOS(Catalina version:10.15.4)
160
+ - output is g++ -v
161
+
169
162
  ```
163
+  Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
164
+  Apple clang version 11.0.3 (clang-1103.0.32.59)
165
+  Target: x86_64-apple-darwin19.4.0
166
+  Thread model: posix
167
+  InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
168
+ ```
170
169
 
170
+ ## ◆コードを動かすために
171
+ **ディレクトリの作成**
171
172
  ```
172
- # コードを動かすために
173
- # ディレクトリの作成
174
173
  mkdir sample_test_python_c_api && cd sample_test_python_c_api
175
174
  There are two files in the directory: main.cpp and python_code_sample.py.
175
+ ```
176
176
 
177
- #作成されたpython環境
177
+ ## 作成されたpython環境
178
- 1. pyenv local anaconda3-5.0.1
178
+ 1. `pyenv local anaconda3-5.0.1`
179
- 2. conda create -n your_env_name python=3.8 anaconda
179
+ 2. `conda create -n your_env_name python=3.8 anaconda`
180
- 3. pyenv local anaconda3-5.0.1/envs/your_env_name
180
+ 3. `pyenv local anaconda3-5.0.1/envs/your_env_name`
181
-
181
+ ```
182
182
  export PYTHONHOME=/Users/username/.pyenv/versions/anaconda3-5.0.1/envs/your_env_name
183
183
  export PYTHONPATH=$PYTHONHOME/bin
184
184
 
185
+ ```
186
+
185
- #cコンパイル
187
+ ## cコンパイル
188
+ ```
186
189
  g++ -fPIC main.cpp $(python3.8-config --cflags --ldflags) -lpython3.8 -o main && ./main
187
190
 
188
191
  python3.8-config --cflags