在Jupyter中:
tf.__path__
_NamespacePath(['C:\Users\Lior\AppData\Roaming\Python\Python39\site-packages\tensorflow'])
type(tf.__path__)
在ipython:
tf.__path__
['c:\python\python39\lib\site-packages\keras\api\_v2',
'C:\Users\Lior\AppData\Roaming\Python\Python39\site-packages\tensorflow_estimator\python\estimator\api\_v2',
'C:\Users\Lior\AppData\Roaming\Python\Python39\site-packages\tensorboard\summary\_tf',
'c:\python\python39\lib\site-packages\tensorflow',
'c:\python\python39\lib\site-packages\tensorflow\_api\v2']
Jupyter:
import tensorflow as tf
import numpy as np
print(np.array(dir(tf)))
[">doc">文件">加载程序'规格']
在ipython:
import tensorflow as tf; import numpy as np; print(np.array(dir(tf)))
["聚合方法"断言"CriticalSection"DType"DeviceSpec"GradientTape"Graph"IndexedSlices"indexed SlicesSpec"Module"操作"OptionalSpec"RaggedTensor"RaghedTensorSpec"RegisterGradient"稀疏张量"稀疏TensorSpec"张量"TensorArray"TensorArraySpec"TensorShape"TensorSpec"TypeSpec"UnconnectedGradients"变量"VariableAggregation"变量同步"_API_MODULE"_LazyLoader">所有">内置">cached"">compiler_version'"">cxx11_abi_flag">doc">文件"">git_version'""内部加载程序"">monolitic_build">名称">1运算符'">包'"'路径'spec'版本"_api"_compat''_current_file_location'_current_module'_distutils''_eestimator_module'_fi'_inspect'_keras_module'_keras_package'"_kernel_dir"_ll"_logging"_major_api_version"_module_dir"'_module_util'_names_with_underscore'_os'_plugin_dir''_running_from_pip_package''_s'_site'_site_packages_dirs'_sys''_tf2''_tf_api_dir''_tf _dir''_typing''abs''acos''acosh''add'"add_n"argmax"argmin"argsort"as_dtype"as_string"asin"asinh"'assert_equal'assert_greater'assert_less'assert_rank'atan'"atan2"atanh"音频"autodiff"签名"batch_to_space"bfloat16"bitcast"bitwise"bool"boolean_mask"broadcast_dynamic_shape"broadcast _static_shape"brodcast_to"大小写"cast"clip_by_global_norm"clit_by_normam"clip-by_value"compat"complex"complex128"complex 64"concat"cond"config"constant"constant_initializer"control_dependences"convert_to_sensor"cos"cosh"cumsum"custom_radient"data"debugging"device"distribute"divide"double"dtensor"dtypes"dynamic_partition"dynamic_stice"edit_distance"eig"eivals"einsum"ensure_shape"equal"errors"estimulator"executing_allely"exp"expand_dims"实验"extract_volume_patches"eye"feature_column"fill"fingerprint"float16"floate32"float 64"floor"foldl"foldr"function"collecte"gather_nd"get_current_name_scope"get_logger"get_static_value"grad_pass_through"gradients"graph_util"greater"greater_equal"group"guarantee_const"half"hessians"histogram_fixed_width"histogram_fixed.width_bins"标识"identity_n"image"import_graph_def"init_scope"initializers"inside_function"int16"int32"int64"int8"io"is_tensor"keras"less"less_equal"linalg"linspace"lite"load_library"'load_op_library'logical_and'logical_not'logical_or'lookup'"loss"make_ndarray"make_tensor_proto"map_fn"math"matmul"matrix_square_root"最大"网格"度量"最小"mlir"multiply"name_scope"negative"nest"newaxis"nn"nogradient"no_op"nondifferential_batch_function"norm"not_equal"numpy_function"one_hot"ones"ones_initializer"one_like"优化器"pad"parallel_stack"pow"print"profiler"py_function"秦t16"秦t32"秦t8"量化"队列"quint16"quint8"粗糙"随机"random_index_shuffle"random_normal_initializer"random_uuniform_initializer"range"rank"raw_ops"realdiv"recompute_grad"reduce_all"reduct_any"'reduce_logsumexp''reduce_max'reduce_mean'reduce_min'reduce_prod'"reduce_sum"register_tensor_conversion_function"repeat"required_space_to_batch_paddings"重塑"资源"反向"reverse_sequence"roll"round"saturate_cast"saved_model"scalar_mul"scan"scatter_nd"searchsorted"sequence_mask"sets"shape"shape_n"sigmoid"sign"signal"sin"sinh"size"slice"排序"space_to_batch'"space_to_batch_nd"稀疏"拆分"sqrt"square"crush"stack"stop_radient"striped_slice"string"string"减法"summary"switch_case"sysconfig"tan"tanh"'tensor_scatter_nd_ad''tensor_skatter_nd_max'tensor_scatter_nd-min'"tensor_scatter_nd_sub"tensor_scatter_nd_update"tensordot"测试"tile"timestamp"tools"tpu"train"transpose"truediv"truncatediv"truncatemod"元组"type_spec_from_value"types"'uint16''uint32'uint64'uint8'unique_with_counts'"dissol_index"unstack"variable_creator_scope"variant"vectorized_map"版本",其中"while_loop"xla"为零"zeros_initifier"zeros-like"]
如何使jupyter引用正确的tf?
我解决了自己的问题:
import sys
right_path = "c:\python\python39\lib\site-packages"
if sys.path[0] != right_path:
sys.path.insert(0,right_path)
import tensorflow as tf
print(tf.constant(6))